前面对网络管理,也就是端口映射做了一些介绍,下来对数据的管理做做介绍,首先是数据卷,接着是数据卷容器。
# docker run -it -h localhost --name volumes-test1 -v /data centos # -i 终端打开 # -t 提供一个终端 # -h 提供一个主机名 # -v 数据卷 # --name 提供一个名字
[root@localhost /]# ls / anaconda-post.log bin data dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [root@localhost /]# ls -ld /data drwxr-xr-x. 2 root root 6 May 19 02:54 /data [root@localhost /]# ls /data [root@localhost /]#
# docker inspect -f {{.Volumes}} volumes-test1 Template parsing error: template: :1:2: executing "" at <.Volumes>: map has no entry for key "Volumes" # docker inspect -f {{.Config.Volumes}} volumes-test1 map[/data:{}]
# docker inspect volumes-test1|grep mounts -iA 10 "Mounts": [ { "Type": "volume", "Name": "a69026e729a8b176f840cf0313394016cb69356e02287c699d7858afdf67ce3d", "Source": "/var/lib/docker/volumes/a69026e729a8b176f840cf0313394016cb69356e02287c699d7858afdf67ce3d/_data", "Destination": "/data", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" }
# cd /var/lib/docker/volumes/a69026e729a8b176f840cf0313394016cb69356e02287c699d7858afdf67ce3d/_data # cp /etc/centos-release .
# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES af89cada0632 centos "/bin/bash" 11 minutes ago Exited (0) 7 minutes ago volumes-test1 # docker start af af # docker attach af [root@localhost /]# ls /data centos-release [root@localhost /]# cat /data/centos-release CentOS Linux release 7.3.1611 (Core) [root@localhost /]#
# docker run -d -h nginx --name nginx -p 8000:80 -v /var/www/html:/usr/share/nginx/html nginx 37b798573793d33e531b6c50f9030371ca44e7c26c60405216f959722333c166
[root@lol html]# curl localhost <h1>Hello,World</h1> [root@lol html]# curl localhost:8000 <h1>Hello,World</h1> [root@lol html]#
[root@lol html]# curl -I localhost HTTP/1.1 200 OK Date: Fri, 19 May 2017 03:30:15 GMT Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 PHP/5.4.16 Last-Modified: Fri, 19 May 2017 03:24:05 GMT ETag: "15-54fd80db8b3dc" Accept-Ranges: bytes Content-Length: 21 Content-Type: text/html; charset=UTF-8 [root@lol html]# curl -I localhost:8000 HTTP/1.1 200 OK Server: nginx/1.13.0 Date: Fri, 19 May 2017 03:30:20 GMT Content-Type: text/html Content-Length: 21 Last-Modified: Fri, 19 May 2017 03:24:05 GMT Connection: keep-alive ETag: "591e6555-15" Accept-Ranges: bytes
# docker run -it --name volumes-test2 -h localhost --volumes-from volumes-test1 centos [root@localhost /]# ls /data centos-release [root@localhost /]#