Installation behavior of dockers

I am currently trying to understand how Docker handles volume installations and encounters the following behavior, which seems to me to be unbalanced:

It is assumed that we want to set the / var / run directory to a container (as an example), we do the following:

$ docker run -i -t -v /var/run:/test ubuntu:latest /bin/bash 

So far, everything is working fine, and all folders and files located in / var / run are displayed inside the container inside the / test.

Now let's see what happens if we decide to install the / var directory:

 $ docker run -i -t -v /var:/test ubuntu:latest /bin/bash 

However, all host folders inside / var are displayed inside / test. However, after running cd in / test / run, files and directories from the host are not displayed. In other words, Docker does not seem to "recursively" mount subsequent child directories and their contents. Is this Docker's usual behavior?

+5
source share
1 answer

This is not just Docker's usual behavior; this is common behavior on Linux. When you bind a file system to another directory, for example:

 mkdir /tmp/mount mount -o bind /var /tmp/mount 

In the source file system, which exists in the source file system, only files on the target server will be displayed. You will not see the files contained in any child mounts unless you must explicitly link these directories as well:

 mount -o bind /var/run /tmp/mount/run 

This is exactly the behavior that you see with Docker, because it is exactly the same mechanism that Docker uses to expand host directories inside your containers.

+6
source

All Articles