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,
Phil

  • File as command line argument of Docker python app
  • Docker tmpfs volume and increasing size
  • How to restart a single container with docker-compose
  • How to dockerize my play scala app?
  • Disable access to LAN from docker container
  • SQL scripts inside /docker-entrypoint-initdb.d directory are not executed
  • Livereload of ionic 2 with docker-compose instance does not work
  • How to prevent Docker from re-running pip installs every time I modify code [duplicate]
  • Starting multiple services inside Docker container
  • Dokku and log management
  • How do I use Liblas in python in docker without error?
  • Running ubuntu containers on ubuntu host - application with gui
  • 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/startup.sh
    RUN echo "if [ ! -e /license/license.txt ] " >> /bin/startup.sh
    RUN echo "then " >> /bin/startup.sh
    RUN echo "   echo 'missing license'" >> /bin/startup.sh
    RUN echo "exit 1 " >> /bin/startup.sh
    RUN echo "fi " >> /bin/startup.sh
    RUN echo "top " >> /bin/startup.sh
    
    RUN chmod +x /bin/startup.sh
    
    ENTRYPOINT ["/bin/startup.sh"]
    

    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
    [works]
    

    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.