What happened when I use a host volume(bind mounts) and named volume(one type of docker managed volume) at the same time?

I have read the some documents before asking this question:

And I am confused about the following two parts:

  1. bind mounts: Mounting into a non-empty directory on the container
  2. named volume: Populate a volume using a container

Their behavior is completely opposite:

For bind mounts:

If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured by the bind mount.

For named volume:

If you start a container which creates a new volume, as above, and the container has files or directories in the directory to be mounted (such as /app/ above), the directory’s contents are copied into the volume. The container then mounts and uses the volume, and other containers which use the volume also have access to the pre-populated content.

My question is, if I use a VOLUME command in dockerfile to create a named volume, and at the same time, use a bind mount to mount a non exist path into the container, what goes on behind the scenes?

For example:

# in docker file
VOLUME /path/in/container

# when run container
docker run -v /not-exist-dir/in/host:/path/in/container  ... /< image >

I have do some test and the result is:

  1. no anonymous volumes was created in /var/lib/docker/volumes/
  2. the not-exist-dir was created on the host and it is not empty now, I think the Populate a volume using a container has take effects.


  1. why there is no anonymous volumes created as expected?
  2. why the directory’s existing contents(in container side) are not obscured by the bind mount?

what happened behind this scenario?

Source: StackOverflow