1, shared host directory to the container
Docker run-d--name=test-v/opt/test:/usr/databases docker-test
Test is the name of the container, it needs to be unique;-V indicates that a data volume is created and mounted in a container, and the example indicates that the/opt/test directory of the host is mounted to the container's/usr/databases directory; docker-test is the name of the mirror.
2, sometimes need to share the container of the volume, you need to use other ways to access
1) Adopt –volumes-from
The smallest mirror busybox can be used to help implement
1.docker Run--name=storedata-v/data:/usr/data busybox true
Defines a directory map called StoreData, which means that the/data directory of the host is mounted to the container's/usr/data directory. Other containers can be –volumes-from to use the directory
Docker run-d--name=test1--volumes-from storedata docker-test
Docker run-d--name=test2--volumes-from storedata docker-test
2 The different directories are mounted in the same directory by means of the LN link
Ln-s/data/opt/es1/
Ln-s/data/opt/es2/
The example generates a shortcut to the/data directory under both the/opt/es1/and/opt/es2/directories, so access to/opt/es1/data and/opt/es2/data are all/data directories
With the link, you can now map the directory directly with-V.
Docker run-d--name=test3-v/opt/es1/data:/usr/data docker-test
Docker run-d--name=test4-v/opt/es2/data:/usr/data docker-test
In this way, operating the/usr/data directory within the TEST3 and test4 containers is the/data directory of the operating host hosts