[root@hspEdu01 ~]# docker rm -f a3ec a3ec [root@hspEdu01 ~]# docker run -d -p 8080:8080 -v webapps:/usr/local/tomcat/webapps -v webconf:/usr/local/tomcat/conf --name tomcat 7253c7ce0ab9 21795689b90c0447b10250fd3b36b96232188b4f16c88f14a434469cd4e33f0f [root@hspEdu01 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 21795689b90c 7253c7ce0ab9 "catalina.sh run" 3 seconds ago Up 2 seconds 0.0.0.0:8080->8080/tcp tomcat #查看本地所有数据卷 [root@hspEdu01 ~]# docker volume ls DRIVER VOLUME NAME local webapps local webconf [root@hspEdu01 ~]# docker inspect webapps [ { "Driver": "local", "Labels": null, "Mountpoint": "/var/lib/docker/volumes/webapps/_data", "Name": "webapps", "Options": {}, "Scope": "local" } ] [root@hspEdu01 ~]# cd /var/lib/docker/volumes/webapps/_data [root@hspEdu01 _data]# ls [root@hspEdu01 _data]# touch a.html [root@hspEdu01 _data]# vim a.html [root@hspEdu01 _data]# cat a.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <h3>Tomcat</h3> </body> </html>
[root@hspEdu01 _data]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 21795689b90c 7253c7ce0ab9 "catalina.sh run" 2 minutes ago Up 2 minutes 0.0.0.0:8080->8080/tcp tomcat #进入容器 [root@hspEdu01 _data]# docker exec -it 2179 bash root@21795689b90c:/usr/local/tomcat# ls BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webapps.dist work root@21795689b90c:/usr/local/tomcat# cd webapps root@21795689b90c:/usr/local/tomcat/webapps# ls a.html root@21795689b90c:/usr/local/tomcat/webapps# exit exit [root@hspEdu01 _data]# docker restart 2179 2179 [root@hspEdu01 _data]# docker inspect webconf [ { "Driver": "local", "Labels": null, "Mountpoint": "/var/lib/docker/volumes/webconf/_data", "Name": "webconf", "Options": {}, "Scope": "local" } ] [root@hspEdu01 _data]# cd /var/lib/docker/volumes/webconf/_data [root@hspEdu01 _data]# ls Catalina catalina.properties jaspic-providers.xml logging.properties tomcat-users.xml web.xml catalina.policy context.xml jaspic-providers.xsd server.xml tomcat-users.xsd [root@hspEdu01 _data]#
可以发现,宿主机,已经和容器目录建立联系,下面只是把左边的wenapps改成宿主机的文件夹即可
现在我们来装下mysql,不仅涉及到数据卷,还涉及到用户账号的设置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[root@hspEdu01 data]# docker run --name mysql -v /root/mysql/data:/var/lib/mysql -v /root/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 --privileged=true -d mysql:5.7 95628d5d89c5c1513e1046bb19181007c2dfc43ea1f3132472ff57f4453fda7b [root@hspEdu01 data]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 95628d5d89c5 mysql:5.7 "docker-entrypoint..." 3 seconds ago Up 2 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql [root@hspEdu01 data]# cd /root [root@hspEdu01 ~]# ls anaconda-ks.cfg data data2 initial-setup-ks.cfg mysql 公共 模板 视频 图片 文档 下载 音乐 桌面 [root@hspEdu01 ~]# cd mysql/ [root@hspEdu01 mysql]# ls conf.d data [root@hspEdu01 mysql]# cd conf.d/ [root@hspEdu01 conf.d]# ls [root@hspEdu01 conf.d]# cd ../data/ [root@hspEdu01 data]# ls auto.cnf ca.pem client-key.pem ibdata1 ib_logfile1 mysql private_key.pem server-cert.pem sys ca-key.pem client-cert.pem ib_buffer_pool ib_logfile0 ibtmp1 performance_schema public_key.pem server-key.pem [root@hspEdu01 data]#