1. The data from the host to mount three ways container
Docker provides three ways to mount the data from the host to the container: • Volumes: Docker part of the host file system management (/ var / lib / docker / volumes). The best way to save the data. • bind mounts: an arbitrary location on the host file or directory is mounted to the container. • tmpfs: Mount stored in the memory of the host system, and does not write the host file system. If you do not want to store data persistently stored in any location, you may be used tmpfs, while the container can avoid writing the write layer to improve performance.
2.Volume
Create Volume: Docker the Create Volume nginx-Vol Viewing Volume: Docker Volume LS Docker Volume Vol the Inspect nginx- mounted volume: Docker RUN -d -p 89:80 --name = src = --mount the Test-nginx nginx-Vol, = dst / usr / report this content share / nginx / HTML nginx Docker RUN 89:80 --name = -d -p -v nginx nginx-the Test-Vol: / usr / report this content share / nginx / HTML nginx delete volume: Docker RM -f $ (PS Docker -a | awk '{}. 1 Print $') Docker RM -f $ (PS -qa Docker) Docker volume Vol RM-Nginx Note: 1. If no volume is created automatically. 2. It is recommended to use --mount, more general
3.Bind Mounts
Create a container volume: Docker RUN = -d Expediting IT --name Nginx-Test type = --mount the bind, the src = / App / wwwroot, DST = / usr / Share / Nginx / HTML Nginx Docker RUN -d Expediting IT --name = nginx-test -v / app / wwwroot: / usr / share / nginx / html nginx authentication binding: Docker Test Inspect Nginx- cleaning: Docker Nginx-STOP Test Docker Nginx RM-Test Note: 1. If the source file / directory does not exist, does not automatically create, will throw an error. 2. If the target container mount nonempty directory, the directory will be hidden existing content [the root @ localhost ~] # mkdir wwwroot; Touch wwwroot / index.html [the root @ localhost ~] -d RUN # Docker - 89:80 = --mount of the type the bind the p-, src = $ PWD / wwwroot, dst = / usr / report this content share / nginx / HTML nginx 9c675487b319d6a723f2de35abd09c465aca6472b91e7232a9de6893012f3f63 [the root @ localhost ~] PS # Docker CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9c675487b319 nginx "nginx -g 'daemon of…" 9 seconds ago Up 8 seconds 0.0.0.0:89->80/tcp sad_robinson [root@localhost ~]# docker exec -it 9c675487b319 bash root@9c675487b319:/# ls /usr/share/nginx/html index.html root@9c675487b319:/# cat /usr/share/nginx/html/index.html root@9c675487b319:/# exit exit [root@localhost ~]# cat wwwroot/index.html [root@localhost ~]# echo "hello" >wwwroot/index.html [root@localhost ~]# docker exec -it 9c675487b319 cat /usr/share/nginx/html/index.html hello [root@localhost ~]# docker rm -f 9c675487b 9c675487b [root@localhost ~]# cat wwwroot/index.html hello [root@localhost ~]#