Management and use of the data volume docker

Using data volume, the database can guarantee that if the container there is a problem but the data is not lost role, such as data in MySQL / date

index.html in the root directory or Nginx

View data volumes

[root@docker ~]# docker volume ls

DRIVER              VOLUME NAME

Create a data volume

[root@docker ~]# docker volume create nginx-vol

nginx-vol

View have created a group called nginx-vol data volumes

[root@docker ~]# docker volume ls

DRIVER              VOLUME NAME

local               nginx-vol

For more information see data volumes

[root@docker ~]# docker volume inspect nginx-vol

Running a call nginx-test container and mount the data volume, source directory nginx-vol target directory Nginx of html the root page

[root@docker ~]# docker run -itd --name nginx-test --mount src=nginx-vol,dst=/usr/share/nginx/html nginx

8ea39f5eb3fac2d85039314117985abd5f6393548a0eb45e27946c424ebebfe8

To the web directory View

[root@docker ~]# docker exec -it nginx-test bash

root@8ea39f5eb3fa:/# cd /usr/share/nginx/html/

root@8ea39f5eb3fa:/usr/share/nginx/html# ls

50x.html  index.html

To mount the directory to see if there are already a data volume

[root@docker ~]# cd /var/lib/docker/volumes/

[root@docker volumes]# ls

metadata.db  nginx-vol

[root@docker volumes]# cd nginx-vol/

[root@docker nginx-vol]# ls

_data

[root@docker nginx-vol]# cd _data/

[root@docker _data]# ls

50x.html  index.html

Delete all container to view the database there

[root@docker ~]# docker rm -f $(docker container ls -qa)

8ea39f5eb3fa

5deb5f032783

4c6e1ee32733

 

[root@docker volumes]# cd nginx-vol/_data/

[root@docker _data]# ls

50x.html  index.html

 

In just run a container and specify the port mapping

[root@docker _data]# docker run -itd --name nginx-test -p 89:80 --mount src=nginx-vol,dst=/usr/share/nginx/html nginx

6f6a742b02272b1eff38974e633e84033f257d6e1b8097c4b60202f1d3b6c451

In the data volume directory and create a a.html file viewing, here it is to play the role of persistent data volumes mounted

[root@docker _data]# curl 192.168.30.22:89

23456

[root@docker _data]# vim a.html

[root@docker _data]# curl 192.168.30.22:89/a.html

<h1>hello</h1>

 

I switched to add a port mapping, so imagine if you start 100 of such containers, are using this data volumes, scalability is very strong, but different ports

[root@docker ~]# docker run -itd --name nginx-test2 -p 90:80 --mount src=nginx-vol,dst=/usr/share/nginx/html nginx

8e3f213e652b31daef38f169240d2388386afeada29ff3367e712ccc98163f49

[root@docker _data]# curl 192.168.30.22:90

23456

[root@docker _data]# curl 192.168.30.22:90/a.html

<h1>hello</h1>

Guess you like

Origin www.cnblogs.com/zc1741845455/p/11078845.html