Best way to pass config file during Docker build

My app requires a license file to run. I don’t want to include this in the Docker image I’m going to distribute. I was hoping users should be able to provide their license file by mounting it as a volume during Docker run. What I’m after is a way to transiently provide a license file to the Docker during the build phase. I can’t mount volumes during this phase. Is there a standard pattern for performing this kind of thing ?
In short , I need to provide a dependent transient file during build, so that the build completes, but that file isn’t included in the final image.

Any insights gratefully received,

  • when mounting volume, directory is empty in docker
  • Code from different git branches in one Python test
  • Cannot reach files found on host with Docker (Failed to open stream: Connection timed out)
  • How to we login to docker hub(private registry) using chef recipe?
  • jenkins job triggering downstram job with paramenters not working
  • Restart failed Selenium browser
  • Running SonarQube with Docker in CI/CD pipeline
  • Docker 1.12-how to run a post deploy script after swarm deploy my service
  • Docker: go get from a private GitHub repo
  • Update a Docker Image on an EC2 Instance
  • how to set max_execution_time php-fpm docker image?
  • How to override the CMD command in the docker run line
  • 3 Solutions collect form web for “Best way to pass config file during Docker build”

    In your Dockerfile‘s build step, you would have to copy in the transient file and then delete it. It’s important that this is done in the same RUN command, otherwise the transient file might end up in a cached union FS…which would probably be against the licensing, if that’s what said transient file is.

    Something like this:

    RUN curl url/to/transient_file -o /containter/path/to/transient_file \
     && your_build_steps \
     && rm -f /container/path/to/transient_file

    What you want is an image that when built doesn’t include the license file. It needs to be added each time the container starts.

    I can think of several ways of doing this, the most obvious is to look for a mounted volume of a fixed name containing the license file at startup, and if not found exit with a message.

    This Dockerfile illustrates the idea

    FROM ubuntu:14.04
    RUN echo "#!/bin/bash" >> /bin/
    RUN echo "if [ ! -e /license/license.txt ] " >> /bin/
    RUN echo "then " >> /bin/
    RUN echo "   echo 'missing license'" >> /bin/
    RUN echo "exit 1 " >> /bin/
    RUN echo "fi " >> /bin/
    RUN echo "top " >> /bin/
    RUN chmod +x /bin/
    ENTRYPOINT ["/bin/"]

    Running this without a license director will cause it to not start.
    Running with a license will run top forever.

    > docker run -it test
    missing license
    > docker run -v `pwd`/license:/license -it test

    You could specify it in an environment variable file

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.