Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Dockerfile: VOLUME declaration before COPY or ADD of multiple files or whole directory adds to the image #21728
docker build and Dockerfile does not respect VOLUME if COPY or ADD move in multiple files or a whole directory. If a single file is specified in either COPY or ADD it works as expected. The file is available during the build and then not present in the image.
BUG REPORT INFORMATION
Steps to reproduce the issue:
Describe the results you received:
Describe the results you expected:
Additional information you deem important (e.g. issue happens only occasionally):
I think "No such file or directory" is the correct result to expect, at least according to https://docs.docker.com/engine/reference/builder/#volume which states "Note: If any build steps change the data within the volume after it has been declared, those changes will be discarded."
In this case
single files aren't discarded for me:
Perhaps this is a documentation issue then, because I think this works as I've come to expect it.
IMHO the documentation is stating that if you mount a container, and think you can copy extra files or changes to it -- those will be ignored because you really cannot do anything to the volume until the container is actually created.
When you execute
Is the expected behavior that any
@senk How strange, I'm not able to repeat the single file method anymore. I'd swear I was able to get it to work at one point.
It seems rather counter intuitive that
results in /user/.ssh having only id_rsa in it while:
RUN ssh-keyscan -t rsa github.com 2>&1 > /user/.ssh/known_hosts
results in both files being in /user/.ssh/
It makes it very difficult to get temporary scripts and source files into a build without bloating the image or exposing rsa keys. The best alternative is to use docker run and commit when you're done.