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,

  • Adding mbstring to docker image for laravel 5 app
  • How to develop a LAMP web application using Docker, Puppet and Vagrant?
  • docker rabbitmq crashing during startup
  • What is a sparse block device at /dev/xvdf
  • Docker gd module for PHP 7
  • AWS Mesosphere: parameters for docker daemon
  • Redirect traffic from docker container into localhost
  • Vagrant: Sync folder with boot2docker box on Windows
  • docker mysql persistent storage
  • Docker stats 100% memory
  • Flask app doesn't retrieve data from same database as unit tests
  • Connect to redis inside bridge network
  • 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.