6.12 docker (b) of the host to mount directories

Mount Hosting Directory

A master data directory as a mount volume

[root@node ~]# mkdir -p /src/webapp
[root@node ~]# docker run -d -P --name web -v /src/webapp:/opt/webapp --mount type=bind,source=/src/webapp,target=/opt/webapp training/webapp python app.py

The above command to load the host  /src/webapp directory into a container  /opt/webappdirectory. This feature is very convenient when carrying out tests, such as the user can place some programs to a local directory, to see whether the container is working properly. Local directory path must be an absolute path, previously used  -v parameter Docker if local directory does not exist automatically creates a folder for you now use  --mount parameter if local directory does not exist, Docker will complain

[root@node ~]# docker run -d -P  --name web -v /src/webapp:/opt/webapp:ro --mount type=bind,source=/src/webapp,target=/opt/webapp,readonly  training/webapp    python app.py

Added  readonly later, it mounted as  只读 a. If you are in the container  /opt/webapp directory new file, it will display the following error

[root@node ~]# /opt/webapp # touch new.txt
touch: new.txt: Read-only file system

View the data volume of specific information

[root@node ~]# docker inspect web

Mount a local host file as a data volume

[root@node ~]# docker run --rm -it -v $HOME/.bash_history:/root/.bash_history --mount type=bind,source=$HOME/.bash_history,target=/root/.bash_history ubuntu:18.04 bash

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/guogle/p/11018823.html