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,

  • Tomcat gets stuck on Deploying web application directory [/usr/local/tomcat/webapps/ROOT.war] (DOCKER)
  • DOCKER for setting up BitBucket
  • Docker base image filesystem
  • Access Right Issue with Docker WordPress Volume mounted on network share
  • Restart docker container from another container
  • Apache docker container - Invalid command 'RewriteEngine'
  • How to connect to mysql running in container from host machine
  • How to deploy secure web application using docker on bluemix
  • Connecting a Dockerized MongoDb instance, behing a reverse Nginx proxy on EC2
  • apachectl -DFOREGROUND exits immediately
  • Allow more cpus with docker-compose up
  • What is the entry point/command required to run an etcd container in ECS?
  • 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.