I can't see the content of the mounted disk in the Docker volume


In docker-compose.yaml I have mounted directory /var/www/ (for clarity I will name this directory as /foo/bar/) as volume /var/www/ in my Docker container (to have Apache document root directory from host available in Docker container).

docker-compose.yaml file:

      - /foo/bar/:/var/www/

It worked very well until now. Now I had to enlarge space for websites and mounted new disk partition into /foo/bar/hdd2 in host. New partition is mounted as /foo/bar/hdd2

cat /proc/mounts | grep hdd2
/dev/vdb1 /foo/bar/hdd2 ext4 rw,relatime 0 0

But I do not see content of /foo/bar/hdd2 in Docker container, the directory /var/www is empty even though there are files/directories in the directory in host environment.

Docker container’s /var/www/hdd2 content:

root@http:/var/www/hdd2# ls -la
total 8
drwxr-xr-x  2 www-data www-data 4096 May 27 19:03 .
drwxrwxr-x 23 www-data www-data 4096 May 27 19:03 ..

Is there any reason why I can’t see the content of the directory linked to the new disk partition in the Docker container’s volume directory?

You actually use bind and not really a named volume.

You need to make sure /dev/vdb1 is mounted before the container starts, to actually see it inside the container. Furthermore, you could also configure the bind propagation, so that the container becomes aware when mount points within the bound folder change. In your case all propagations except private and rprivate should work. I would try slave or rslave (note: those are the actual values taken from the documentation)