You do this during build:
RUN touch /var/log/node.log && / node --help 2>&1 > /var/log/node.log
The file /var/log/node.log
is created and fixed invariably in the resulting image.
Then you start the container with this mount volume:
volumes: - ./mongo/log/:/var/log/
Everything that is in ./mongo/log/
is mounted as /var/log
in the container, which hides everything that was before (from the image). This is what makes it look like your touch
didn't work (although it probably worked fine).
You think about it backwards - your mount of the volume does not display the version of the /var/log
container from the outside - it replaces everything that was there.
Nothing you do in Dockerfile (build) will ever appear in an external mount.
source share