Dockerfile; docker build volumes: changes to volume via ADD or COPY are not discarded

Viewed 727

I have a dockerfile with something like:

VOLUME /tmp/space
ADD local/directory/ /tmp/space/
RUN cp /tmp/space/somescript.sh /opt/real/space/

After the container is built and I get an interactive shell I notice that the /tmp/space still contains the data from local/directory.

If I add a RUN rm -rf /tmp/space/* to the end of the dockerfile and get shell access. The data is still there in /tmp/space/.

As a result, I'm left making a running container using the same volume and then committing the changed container to an updated image.

Is there a method to, during the build, have a temporarily loaded volume that doesn't bloat the resulting image?

The goal is to use source files and scripts to perform some actions during a build. The layers of docker end up recording a duplicate of the COPY/ADD step with the RUN step. So it would be better to COPY the data into a space that isn't recorded as a layer then as a single RUN step cp stuff && execute scripts to save on space.

1 Answers
Related