Docker自学文档
学前零星使用操作
一、基础镜像篇
二、基础容器篇
三、容器数据卷
四、DockerFile构建镜像
五、网络篇
六、Docker Compose
docker 在已经启动的容器中开启端口映射
ubuntu22.04使用docker-compose部署最美博客系统
本文档使用 MrDoc 发布
-
+
home page
三、容器数据卷
## 1、什么是容器数据卷 容器之间可以有一个数据共享的技术!Docker容器中产生的数据,同步到本地! 这就是卷技术!目录的挂载,将我们容器内的目录,挂载到Linux上面!容器间也是可以数据共享的! #### 1.1、使用-v挂载数据卷 方式一:使用命令方式来挂载 ``` docker run -it -v 主机目录:容器内目录 /bin/bash ``` ##### 1.1.1、创建一个centos 容器宿主机/ceshi目录与容器/home目录映射 ``` [root@localhost ceshi]# docker run --name centos -d -it -v /ceshi/:/home centos:latest ef3d9b839548e24c666d50120409f5f63fecd28eb91f5602e7d35b8ed1172c1f [root@localhost ceshi]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ef3d9b839548 centos:latest "/bin/bash" 5 seconds ago Up 2 seconds centos ``` 在宿主机/ceshi目录下新增一个文件test.txt,并在容器对应的目录下查看 ``` [root@localhost ceshi]# touch test.txt [root@localhost ceshi]# ls test.txt [root@localhost ceshi]# docker exec -it centos bash [root@ef3d9b839548 /]# ls /home/ test.txt [root@ef3d9b839548 /]# ``` 查看容器对应的挂载信息 ``` [root@localhost ceshi]# docker inspect centos ……… #省略前面部分 "Mounts": [ #挂载信息 { "Type": "bind", "Source": "/ceshi", #宿主机目录地址 "Destination": "/home", #容器内部目录地址 "Mode": "", "RW": true, "Propagation": "rprivate" } ……… #省略后面部分 ``` ##### 1.1.2、创建一个nginx 本次实验以自己构建的nginx镜像,操作要求目录挂载如下: /usr/local/nginx/html:/usr/local/nginx/html #静态资源站点目录 /usr/local/nginx/conf.d:/usr/local/nginx/conf.d #子配置文件目录 /usr/local/nginx/logs:/usr/local/nginx/logs #日志目录 /usr/local/nginx/conf/nginx.conf:/usr/local/nginx/conf/nginx.conf #主配置文件目录 (1)宿主机创建对应目录 ``` [root@localhost ~]# mkdir -p /usr/local/nginx/{conf.d,conf,html,log} ``` (2) 临时启动一个nginx容器 ``` [root@localhost ~]# docker run --name nginx_ceshi -d -it -p 81:80 nginx:1.25.1 52ead4d72591f2b00ed7ebf96dfd13619f49c70915688d1ba5160ce88eea192b [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 52ead4d72591 nginx "/docker-entrypoint.…" 4 seconds ago Up 2 seconds 0.0.0.0:81->80/tcp, :::81->80/tcp nginx_ceshi ``` (3)把容器内的nginx主要文件拷贝至宿主机对应目录下 ``` #日志文件 docker cp nginx_ceshi:/usr/local/nginx/logs/access.log /usr/local/nginx/logs/ #报错文件 docker cp nginx_ceshi:/usr/local/nginx/logs/error.log /usr/local/nginx/logs/ #主配置文件 docker cp nginx_ceshi:/usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/ #50x文件 docker cp nginx_ceshi:/usr/local/nginx/html/50x.html /usr/local/nginx/html/ #首页文件 docker cp nginx_ceshi:/usr/local/nginx/html/index.html /usr/local/nginx/html/ ``` (4)删除临时容器 ``` [root@localhost conf]# docker rm -f nginx_ceshi ``` (5)启动容器并挂载目录 ``` docker run --name nginx -it -d -p 80:80 \ -v /usr/local/nginx/html:/usr/local/nginx/html \ -v /usr/local/nginx/conf.d:/usr/local/nginx/conf.d \ -v /usr/local/nginx/logs:/usr/local/nginx/logs \ -v /usr/local/nginx/conf/nginx.conf:/usr/local/nginx/conf/nginx.conf nginx:1.25.1 ``` 容器内创建子配置文件目录,保持与挂载一致 ``` [root@localhost ~]# docker exec -it nginx bash [root@bb1abe8366d5 nginx-1.25.1]# mkdir -p /usr/local/nginx/conf.d ``` (6)修改首页文件内容并测试效果 ``` [root@localhost ~]# echo this is new nginx web site > /usr/local/nginx/html/index.html ``` 浏览器访问效果 ![](/media/202309/image-20230809114919583.png) 查看nginx日志文件访问情况 ![](/media/202309/image-20230809121719007.png) ##### 1.1.3、创建一个mysql 思考:MySQL的数据持久化问题。防止因为删除容器而导致数据删除,做目录挂载。 (1)查看并拉取mysql镜像 ``` [root@localhost ~]# docker search mysql:5.7 NAME DESCRIPTION STARS OFFICIAL AUTOMATED migs/mysql-5.7 mysql:5.7 plus some basic enhancements 0 [OK] idyci/mysql mysql:5.7.25 1 xiao806852034/mysql57 基于 mysql:5.7 0 framgiaciteam/mysql-256 FROM mysql:5.7 CMD ["--block_encryption_mod… 0 metatronx/mysql mysql:5.7 + druid account & database 0 haswind/mysql mysql:5.7 0 stsiwo/sts-blog-db base image mysql:5.7.28 0 alexmbarbosa/mysql5.7 Based on official mysql:5.7 docker image 1 llasuka/mysql mysql:5.7 0 michaelzx/docker_msyql without ONLY_FULL_GROUP_BY base on mysql:5.7… 0 [OK] alecchyi/mysql mysql:5.7 for demo 0 denghui/mysql mysql:5.7-tz.8 0 [OK] crbanman/mysql-tmpfs A docker image based off of mysql:5.7 that m… 0 vigasin/mysql Clone of official mysql:5.7 image, that allo… 0 variu/hyperledger-explorer-mysql mysql:5.7.23 for hyperledger explorer 0 doctorva/mysql_fede Based on Mysql:5.7 and add new configuration… 0 beyondray/kbengine-mysql kbengine auto-build env from mysql:5.7 0 [OK] zhjs/mysql mysql:5.7 0 ahmedelshfie/spring-boot-mysql-rest-api mysql:5.7 0 liyupei/mysql Mysql:5.7 0 kamatimaru/mysql57-ja Added Japanese support settings to mysql:5.7… 0 dockerzm/mysql docker run --name mysql -e MYSQL_ROOT_PASSWO… 0 ruyli/mysql mysql:5.7 0 zeq9069/mysql_service mysql:5.7 0 zhangruihuai/mysql-node-nginx-python based on mysql:5.7 MySQL 5.7 NodeJS v14.18.… 0 [root@localhost ~]# docker pull mysql:5.7 5.7: Pulling from library/mysql 72a69066d2fe: Pull complete 93619dbc5b36: Pull complete 99da31dd6142: Pull complete 626033c43d70: Pull complete 37d5d7efb64e: Pull complete ac563158d721: Pull complete d2ba16033dad: Pull complete 0ceb82207cd7: Pull complete 37f2405cae96: Pull complete e2482e017e53: Pull complete 70deed891d42: Pull complete Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94 Status: Downloaded newer image for mysql:5.7 docker.io/library/mysql:5.7 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql 5.7 c20987f18b13 19 months ago 448MB hello-world latest feb5d9fea6a5 22 months ago 13.3kB ``` (2)创建并启动一个容器,注意启动mysql需要配置环境,配置登录密码,否则无法使用,查阅官方资料,使用参数:-e MYSQL_ROOT_PASSWORD= ``` [root@localhost ~]# docker run -d -it --name mysql -p 3306:3306 \ -v /home/mysql/conf:/etc/mysql/conf.d \ -v /home/mysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=0000 mysql:5.7 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3c75b4179d4a mysql:5.7 "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql ``` (3)使用工具Navicat链接 ![](/media/202309/image-20230809152440174.png) ![](/media/202309/image-20230809152456300.png) (4)测试创建数据库,并在宿主机上查看 ![](/media/202309/image-20230809160305292.png) ``` [root@localhost 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 test ``` #### 1.2、具名和匿名挂载 1.2.1、匿名挂载 ``` # 匿名挂载 -v 容器内路径 docker run -d -P --name nginx01 -v /etc/nginx nginx:latest #-P(大P)随机映射端口 # 查看容器所有的volume的情况 [root@localhost ~]# docker volume ls DRIVER VOLUME NAME local 4cb36d1ec057cf8d1527c0cd0d0aa95be7c5f7e442261663360b9f5e2692c0ae local 6fdd14f9e36c7f7085bcff95356b81ced251e164353123d8830ef7377d55e419 local 7e6b9a1f6126d9719603e6463f1e507d1297c138f080730c2d904993d8cf2ba9 local 21f17b4bfd4e881b9ef22b000f3fb9553593a5f2937b2b133442ff95049e49d8 local 76ac5e92ba2675eb17056634ca651d3fa13787ee1e6e46d0ca0d867a9333c0a5 local 150e65fcdafd0470cbff91129f3da6b3e8e30f9c3542d49e1b51a8ea9da3f90d local 842b6b1caec13601db7e93bd67970e751673110f328de16ce1bd6dfce1fe827b local 2750f4a53402bf3f72a8f5858beb9623776d71473908019b82718d260bdd3928 local 9089aca76279a28ba7416c88896f5ca3ef5798c391ab7f11be50f5af98533427 local 410664d8ac8c5cc2906360b5220e1de824a4cbe534ee7aab7ae38aeee34e2788 local ba31c0deca297ea1cdc58e33c3d314f8321632732539bcc26afed59716c301e0 local f7f472685707da4d371efed0ae2f53f05e163231091866eca9244799b1edf207 local f304255ca5805e362f5d4b5cdc209e7be7a27a9aac64199827a9b11a83518703 # 这里发现就是匿名挂载,在-v的时候写了容器内路径,没有写宿主机路径 ``` 1.2.2、具名挂载 ``` # 具名挂载 -v 卷名:容器内路径 [root@localhost ~]# docker run -d -P --name nginx02 -v nginx02:/etc/nginx nginx:latest #-P(大P)随机映射端口 3bf0b230cfe538446774d1f744bb4f75e75373a362ec8bb279f0a5c93db15a2e # 查看容器所有的volume的情况 [root@localhost ~]# docker volume ls DRIVER VOLUME NAME local 4cb36d1ec057cf8d1527c0cd0d0aa95be7c5f7e442261663360b9f5e2692c0ae local 6fdd14f9e36c7f7085bcff95356b81ced251e164353123d8830ef7377d55e419 local 7e6b9a1f6126d9719603e6463f1e507d1297c138f080730c2d904993d8cf2ba9 local 21f17b4bfd4e881b9ef22b000f3fb9553593a5f2937b2b133442ff95049e49d8 local 76ac5e92ba2675eb17056634ca651d3fa13787ee1e6e46d0ca0d867a9333c0a5 local 150e65fcdafd0470cbff91129f3da6b3e8e30f9c3542d49e1b51a8ea9da3f90d local 842b6b1caec13601db7e93bd67970e751673110f328de16ce1bd6dfce1fe827b local 2750f4a53402bf3f72a8f5858beb9623776d71473908019b82718d260bdd3928 local 9089aca76279a28ba7416c88896f5ca3ef5798c391ab7f11be50f5af98533427 local 410664d8ac8c5cc2906360b5220e1de824a4cbe534ee7aab7ae38aeee34e2788 local ba31c0deca297ea1cdc58e33c3d314f8321632732539bcc26afed59716c301e0 local f7f472685707da4d371efed0ae2f53f05e163231091866eca9244799b1edf207 local f304255ca5805e362f5d4b5cdc209e7be7a27a9aac64199827a9b11a83518703 local nginx02 <------这里就是具名字 # 查看下这个卷在宿主机哪个路径,通过inspect [root@localhost ~]# docker volume inspect nginx02 [ { "CreatedAt": "2023-08-09T16:17:41+08:00", "Driver": "local", "Labels": null, "Mountpoint": "/var/lib/docker/volumes/nginx02/_data", "Name": "nginx02", "Options": null, "Scope": "local" } ] ``` 所有的docker容器内的卷,没有指定目录的情况下都是在`/var/lib/docker/volumes/[v-name]/_data`下 ``` [root@localhost ~]# ls /var/lib/docker/volumes 150e65fcdafd0470cbff91129f3da6b3e8e30f9c3542d49e1b51a8ea9da3f90d 842b6b1caec13601db7e93bd67970e751673110f328de16ce1bd6dfce1fe827b 21f17b4bfd4e881b9ef22b000f3fb9553593a5f2937b2b133442ff95049e49d8 9089aca76279a28ba7416c88896f5ca3ef5798c391ab7f11be50f5af98533427 2750f4a53402bf3f72a8f5858beb9623776d71473908019b82718d260bdd3928 ba31c0deca297ea1cdc58e33c3d314f8321632732539bcc26afed59716c301e0 410664d8ac8c5cc2906360b5220e1de824a4cbe534ee7aab7ae38aeee34e2788 backingFsBlockDev 4cb36d1ec057cf8d1527c0cd0d0aa95be7c5f7e442261663360b9f5e2692c0ae f304255ca5805e362f5d4b5cdc209e7be7a27a9aac64199827a9b11a83518703 6fdd14f9e36c7f7085bcff95356b81ced251e164353123d8830ef7377d55e419 f7f472685707da4d371efed0ae2f53f05e163231091866eca9244799b1edf207 76ac5e92ba2675eb17056634ca651d3fa13787ee1e6e46d0ca0d867a9333c0a5 metadata.db 7e6b9a1f6126d9719603e6463f1e507d1297c138f080730c2d904993d8cf2ba9 nginx02 ``` 查看nginx02的卷目录信息 ``` [root@localhost ~]# ls /var/lib/docker/volumes/nginx02/_data conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params ``` 通过具名挂载可以很方便查找我们的一个卷,大多数情况下使用`具名挂载` #### 1.3、挂载目录权限 ``` # 通过 -v 容器内路径:{ro | rw} 改变读写权限 ro readonly #只读权限,这个路径只能通过宿主机改变,容器内部无法操作 rw readwrite #可读可写(默认权限) # 一旦设置了容器权限,容器对我们挂载出来的内容就有限定了 [root@localhost ~]# docker run -d -P --name nginx03 -v nginx03:/etc/nginx:ro nginx:latest [root@localhost ~]# docker run -d -P --name nginx03 -v nginx03:/etc/nginx:rw nginx:latest ``` #### 1.4、使用DockerFile挂载卷 Dockerfile就是用来构建docker镜像的构建文件!命令脚本!通过这个脚本可以生成一个镜像,镜像是一层一层的,所以命令也是一层一层的。 (1)创建一个目录用来挂载 ``` [root@localhost ~]# mkdir /home/docker-test-volume [root@localhost ~]# cd /home/docker-test-volume/ [root@localhost docker-test-volume]# ``` (2)创建dockerfile文件 ``` [root@localhost docker-test-volume]# vim dockerfile FROM centos:7 VOLUME ["volume01","volume02"] CMD echo "------successful-----" CMD /bin/bash ``` (3)构建镜像 ``` [root@localhost docker-test-volume]# docker build -f /home/docker-test-volume/dockerfile -t ceshi:1.0 . [root@localhost docker-test-volume]# docker build -f /home/docker-test-volume/dockerfile -t ceshi:1.0 . [+] Building 16.1s (5/5) FINISHED docker:default => [internal] load build definition from dockerfile 0.0s => => transferring dockerfile: 191B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/centos:7 16.0s => [1/1] FROM docker.io/library/centos:7@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987 0.0s => => resolve docker.io/library/centos:7@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987 0.0s => => sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987 1.20kB / 1.20kB 0.0s => => sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f 529B / 529B 0.0s => => sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9 2.75kB / 2.75kB 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:c655038184119c5598074af7da884ff39057e5a0c4dfd8173353f9384b53df29 0.0s => => naming to docker.io/library/ceshi:1.0 ``` (4)查看镜像 ``` [root@localhost docker-test-volume]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ceshi 1.0 c65503818411 23 months ago 204MB ``` (5)给自己创建的镜像启动一个容器 ``` [root@localhost ~]# docker run -d -it --name ceshi1 ceshi:1.0 e9c0994ed9644d5f34c105b16208bb9973679d78d0a866dbd2df2189478127f5 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e9c0994ed964 ceshi:1.0 "/bin/sh -c /bin/bash" 3 seconds ago Up 1 second ceshi1 [root@localhost ~]# docker exec -it ceshi1 bash [root@e9c0994ed964 /]# ls anaconda-post.log bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var volume01 volume02 #生成镜像自动挂载的目录 [root@e9c0994ed964 /]# ``` 这个容器内目录一定和宿主机上某个目录同步,脚本内编写为匿名挂载,在volume01写一个文件 ``` [root@e9c0994ed964 /]# cd volume01 [root@e9c0994ed964 volume01]# touch container.txt ``` 查看这个容器信息,查找卷的挂载信息 ``` [root@localhost ~]# docker inspect ceshi1 "Mounts": [ { "Type": "volume", "Name": "47c313b9babba01649163c236b7db9f354f8ae5d8bb86856d0a27bba12e666bd", "Source": "/var/lib/docker/volumes/47c313b9babba01649163c236b7db9f354f8ae5d8bb86856d0a27bba12e666bd/_data", "Destination": "volume02", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" }, { "Type": "volume", "Name": "1e1a872d00ec7ba2958b3a47c26001a683f49ee0db573ee47c9b9ca2e1df11ff", "Source": "/var/lib/docker/volumes/1e1a872d00ec7ba2958b3a47c26001a683f49ee0db573ee47c9b9ca2e1df11ff/_data", "Destination": "volume01", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } 宿主机查看下同步文件是否存在 [root@localhost ~]# ls /var/lib/docker/volumes/1e1a872d00ec7ba2958b3a47c26001a683f49ee0db573ee47c9b9ca2e1df11ff/_data container.txt ``` 这种方式,未来使用的非常多。如果构建镜像的时候没有挂载,要手动镜像挂载 -v #### 1.5、数据卷容器--volumes-from 两个容器实现挂载相同目录,容器间数据共享。例如:mysql数据同步,多个mysql数据同步。关键命令:--volumes-from ![](/media/202309/image-20230810144845638.png) (1)启动3个自己使用dockerfile构建的镜像 #启动第1个容器命名docker01,查看2个数据卷:volume01、volume02 ``` [root@localhost ~]# docker run -d -it --name docker01 ceshi:1.0 2bd3b570631c1fdb5e9b44ba7e07449218e79a354ebdb40e073335654c5244eb [root@localhost ~]# docker exec -it docker01 bash [root@2bd3b570631c /]# ls anaconda-post.log dev home lib64 mnt proc run srv tmp var volume02 bin etc lib media opt root sbin sys usr volume01 [root@2bd3b570631c /]# ``` #启动第2个容器命名docker02,并挂载docker01,查看2个数据卷:volume01、volume02 ``` [root@localhost ~]# docker run -d -it --name docker02 --volumes-from docker01 ceshi:1.0 a4d762a32250ddeb8a47dc54d2bf4808dc5430b045a5c3f2ae82d181024c8a26 [root@localhost ~]# docker exec -it docker02 bash [root@a4d762a32250 /]# ls anaconda-post.log dev home lib64 mnt proc run srv tmp var volume02 bin etc lib media opt root sbin sys usr volume01 [root@a4d762a32250 /]# ``` 我们在docker01的目录volume01下生成一个文件,看看docker对应volume01下会不会存在 ``` #docker01下操作 [root@localhost ~]# docker attach docker01 [root@2bd3b570631c /]# ls anaconda-post.log dev home lib64 mnt proc run srv tmp var volume02 bin etc lib media opt root sbin sys usr volume01 [root@2bd3b570631c /]# cd volume01 [root@2bd3b570631c volume01]# ls [root@2bd3b570631c volume01]# touch docker01 [root@2bd3b570631c volume01]# ls docker01 #docker02下查看 [root@localhost ~]# docker attach docker02 [root@a4d762a32250 /]# cd volume01 [root@a4d762a32250 volume01]# ls docker01 #docker01下创建的数据同步到了docker02下面 [root@a4d762a32250 volume01]# ``` #启动第3个容器命名docker03,并挂载docker01,查看2个数据卷:volume01、volume02 ``` [root@localhost ~]# docker run -d -it --name docker03 --volumes-from docker01 ceshi:1.0 f041c047de6fa82ec5620441ad4a4f02a8f284a9c541b86399648543e97f9f65 [root@localhost ~]# docker exec -it docker03 bash [root@f041c047de6f /]# ls anaconda-post.log dev home lib64 mnt proc run srv tmp var volume02 bin etc lib media opt root sbin sys usr volume01 [root@f041c047de6f /]# cd volume01 [root@f041c047de6f volume01]# ls docker01 #数据同步了 [root@f041c047de6f volume01]# #在docker03的volume02创建一个新文件,然后分别在docker02和docker01下查看 [root@f041c047de6f /]# cd volume02 [root@f041c047de6f volume02]# ls [root@f041c047de6f volume02]# touch docker03 [root@f041c047de6f volume02]# ls docker03 #在docker02下查看 [root@localhost ~]# docker exec -it docker02 bash [root@a4d762a32250 /]# ls volume02 docker03 #docker02下存在docker03创建的文件 #在docker01下查看 [root@localhost ~]# docker exec -it docker01 bash [root@2bd3b570631c /]# ls volume02 docker03 #docker01下存在docker03创建的文件 ``` 多个容器之间配置了数据共享,只要有一个容器存在数据就不会丢失。 ![](/media/202309/image-20230810151518215.png) ##### 1.5.1、多个mysql实现数据共享 ``` # 创建第1个mysql容器,命名mysql01 [root@localhost ~]# docker run -d -it --name mysql01 -p 3306:3306 \ -v /home/mysql/conf:/etc/mysql/conf.d \ -v /home/mysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=0000 mysql:5.7 # 创建第2个mysql容器,命名mysql02 [root@localhost ~]# docker run -d -it --name mysql02 -p 3307:3306 -e MYSQL_ROOT_PASSWORD=0000 --volumes-from mysql01 mysql:5.7 # 创建第3个mysql容器,命名mysql03 [root@localhost ~]# docker run -d -it --name mysql03 -p 3308:3306 -e MYSQL_ROOT_PASSWORD=0000 --volumes-from mysql01 mysql:5.7 #查看所有mysql容器 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dad667c103bf mysql:5.7 "docker-entrypoint.s…" 7 seconds ago Up 3 seconds 33060/tcp, 0.0.0.0:3308->3306/tcp, :::3308->3306/tcp mysql03 35d9139ffd56 mysql:5.7 "docker-entrypoint.s…" 17 seconds ago Up 13 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp mysql02 0f1073961bd1 mysql:5.7 "docker-entrypoint.s…" 40 seconds ago Up 37 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql01 ``` #使用数据库管理工具navict创建一个数据库mysql01,分别在容器mysql02和mysql03上查看 ![](/media/202309/image-20230810153449915.png) ``` # 在容器mysql02上查看 [root@localhost data]# docker exec -it mysql02 bash root@35d9139ffd56:~# ls /var/lib/mysql auto.cnf ca.pem client-key.pem ib_logfile0 ibdata1 mysql performance_schema public_key.pem server-key.pem test ca-key.pem client-cert.pem ib_buffer_pool ib_logfile1 ibtmp1 mysql01 private_key.pem server-cert.pem sys # 在容器mysql03上查看 [root@localhost data]# docker exec -it mysql03 bash root@dad667c103bf:/# ls /var/lib/mysql auto.cnf ca.pem client-key.pem ib_logfile0 ibdata1 mysql performance_schema public_key.pem server-key.pem test ca-key.pem client-cert.pem ib_buffer_pool ib_logfile1 ibtmp1 mysql01 private_key.pem server-cert.pem sys ``` ------
admin
Sept. 19, 2023, 4:53 p.m.
转发文档
Collection documents
Last
Next
手机扫码
Copy link
手机扫一扫转发分享
Copy link
IT集中营导航
IT集中营导航
Markdown文件
share
link
type
password
Update password