I've a base_image Dockerfile with a
VOLUME /var/log

Now I use the base_image in another Dockerfile as base for work_image and there is put some content in /var/log.

But if I start a container with the work_image the volume directory /var/log is empty.
The content of volume is not initialized during image creation how it is documented here:

I've also tried to put another VOLUME /var/log directive in the work_image Dockerfile. But no change.

Is this as bug or how this should work?

Thx Markus

  • How did you start the container? Jul 14, 2020 at 16:03
  • @MichaelHampton With docker-compose or docker start, but there is no additional volume mount or bind. Just the single anonymous volume from the image. Seems to always mount the empty first volume from base and during build of work image, it doesn't recognize the volume from base.
    – Markus
    Jul 14, 2020 at 16:21
  • I expect it's precisely because you're using an anonymous volume. These aren't really expected to be shared. I suspect each container is using a different anonymous volume. I'd poke around with docker container inspect <container> for each container and see what volumes they are using. Jul 14, 2020 at 16:29
  • @MichaelHampton No, there is no sharing of volumes between containers. It is a problem of building the images. Seems that the first VOLUME definition in Dockerfile copies the directory content to a image and any later VOLUME definitions for the same directory is simply and quietly ignored. Sadly there seems to be no debug/verbose output during builds to see what is happening exactly.
    – Markus
    Jul 14, 2020 at 18:06
  • Hmm, interesting. I'd like to play with this a bit. Can you share some trivial Dockerfiles that reproduce the problem? Jul 14, 2020 at 18:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.