Reputation: 161
My application 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.
Upvotes: 4
Views: 9623
Reputation: 39991
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]
Upvotes: 3
Reputation: 9211
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
Upvotes: 2