docker info

  1. [root@xiao docker]# docker info
  2. Client:
  3. Context: default
  4. Debug Mode: false
  5. Plugins:
  6. app: Docker App (Docker Inc., v0.9.1-beta3)
  7. buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
  8. scan: Docker Scan (Docker Inc.)
  9. Server:
  10. Containers: 8
  11. Running: 5
  12. Paused: 0
  13. Stopped: 3
  14. Images: 16
  15. Server Version: 20.10.8
  16. Storage Driver: overlay2
  17. Backing Filesystem: extfs
  18. Supports d_type: true
  19. Native Overlay Diff: true
  20. userxattr: false
  21. Logging Driver: json-file
  22. Cgroup Driver: cgroupfs
  23. Cgroup Version: 1
  24. Plugins:
  25. Volume: local
  26. Network: bridge host ipvlan macvlan null overlay
  27. Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
  28. Swarm: inactive
  29. Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
  30. Default Runtime: runc
  31. Init Binary: docker-init
  32. containerd version: e25210fe30a0a703442421b0f60afac609f950a3
  33. runc version: v1.0.1-0-g4144b63
  34. init version: de40ad0
  35. Security Options:
  36. seccomp
  37. Profile: default
  38. Kernel Version: 3.10.0-1062.1.2.el7.x86_64
  39. Operating System: CentOS Linux 7 (Core)
  40. OSType: linux
  41. Architecture: x86_64
  42. CPUs: 1
  43. Total Memory: 1.795GiB
  44. Name: xiao
  45. ID: SR3Y:RSZT:2ZAE:M33P:O2LT:55KN:A3XY:WE7V:QXJY:7Z32:M34L:NX7N
  46. Docker Root Dir: /var/lib/docker
  47. Debug Mode: false
  48. Registry: https://index.docker.io/v1/
  49. Labels:
  50. Experimental: false
  51. Insecure Registries:
  52. 127.0.0.0/8
  53. Registry Mirrors:
  54. https://4h8ex9ed.mirror.aliyuncs.com/
  55. Live Restore Enabled: false
  56. [root@xiao docker]#
  1. docker version #显示docker的版本信息
  2. docker info #显示docker的系统信息,包括镜像和容器的数量
  3. docker --help

文档地址: https://docs.docker.com/reference/

  1. port # 查看映射端口对应的容器内部源端口
  2. pause # 暂停容器
  3. ps # 容器列表
  4. pull # 从docker镜像源服务器拉取指定镜像或者库镜像
  5. push # 推送指定镜像或者库镜像至docker源服务器
  6. restart # 重启运行的容器
  7. rm # 移除一个或多个容器
  8. rmi # 移除一个或多个镜像 (无容器使用该镜像才可删除,否则需要删除相关容器才可继续或 -f 强制删除)
  9. run # 创建一个新的容器并运行一个命令
  10. save # 保存一个镜像为一个 tar 包【对应 load】
  11. search # 在 docker hub 中搜索镜像
  12. start # 启动容器
  13. stop # 停止容器
  14. tag # 给源中镜像打标签
  15. top # 查看容器中运行的进程信息
  16. unpause # 取消暂停容器
  17. version # 查看 docker版本号
  18. wait # 截取容器停止时的退出状态值
  19. attach # Attach to a running container #当前shell下attach连接指定运行镜像
  20. build # Build an image from a Dockerfile #通过Dockerfile定制镜像
  21. commit # Create a new image from a containers changes #提交当前容器为新的镜像
  22. cp # Copy files/folders from a container to a HOSTDIR or to STDOUT #从容器中拷贝指定文件或者目录到宿主机中
  23. create # Create a new container #创建一个新的容器,同run 但不启动容器
  24. diff # Inspect changes on a containers filesystem #查看docker容器变化
  25. events # Get real time events from the server#从docker服务获取容器实时事件
  26. exec # Run a command in a running container#在已存在的容器上运行命令
  27. export # Export a containers filesystem as a tar archive #导出容器的内容流作为一个tar归档文件(对应import)
  28. history # Show the history of an image #展示一个镜像形成历史
  29. inspect # 查看容器详细信息
  30. kill # kill 指定的容器

镜像命令

  1. docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. <none> <none> 95a86af3f2e7 4 months ago 570MB
  4. jenkins/jenkins latest ba8a0e5dc5cb 4 months ago 570MB
  5. nginx latest d1a364dc548d 4 months ago 133MB
  6. portainer/portainer latest 580c0e4e98b0 6 months ago 79.1MB
  7. hello-world latest d1165f221234 6 months ago 13.3kB
  8. # 解释
  9. REPOSITORY: 镜像仓库源
  10. TAG: 镜像版本信息
  11. IMAGE ID: 镜像的ID
  12. CREATED: 镜像的创建实际爱你
  13. SIZE: 镜像的大小
  14. 可选参数
  15. docker images
  16. -a : (--all) 列出所有镜像
  17. -q : (--quiet) 只显示镜像ID

搜索镜像

  1. docker search mysql
  2. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  3. mysql MySQL is a widely used, open-source relation 11470 [OK]
  4. mariadb MariaDB Server is a high performing open sou 4354 [OK]
  5. mysql/mysql-server Optimized MySQL Server Docker images. Create 848 [OK]
  6. percona Percona Server is a fork of the MySQL relati 555 [OK]
  7. phpmyadmin phpMyAdmin - A web interface for MySQL and M 332 [OK]
  8. centos/mysql-57-centos7 MySQL 5.7 SQL database server 91 [OK]
  9. docker search mysql --filter=STARS=3000 # 搜索start数大于3000的
  10. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  11. mysql MySQL is a widely used, open-source relation 11470 [OK]
  12. mariadb MariaDB Server is a high performing open sou 4354 [OK]

拉取镜像

hub 搜索
image.png

  1. docker pull 镜像名[:tag]
  2. # eg
  3. docker pull mysql
  4. Using default tag: latest # 如果不写tag, 默认就是latest
  5. latest: Pulling from library/mysql
  6. a330b6cecb98: Pull complete # 分层下载,docker image 的核心 联合文件系统
  7. 9c8f656c32b8: Pull complete
  8. 88e473c3f553: Pull complete
  9. 062463ea5d2f: Pull complete
  10. daf7e3bdf4b6: Pull complete
  11. 1839c0b7aac9: Pull complete
  12. cf0a0cfee6d0: Pull complete
  13. 1b42041bb11e: Pull complete
  14. 10459d86c7e6: Pull complete
  15. b7199599d5f9: Pull complete
  16. 1d6f51e17d45: Pull complete
  17. 50e0789bacad: Pull complete
  18. Digest: sha256:99e0989e7e3797cfbdb8d51a19d32c8d286dd8862794d01a547651a896bcf00c # 签名
  19. Status: Downloaded newer image for mysql:latest
  20. docker.io/library/mysql:latest # 真实地址
  21. docker pull mysql
  22. 等价于
  23. docker pull docker.io/library/mysql:latest
  24. # 指定tag
  25. docker pull mysql:5.7
  26. 5.7: Pulling from library/mysql
  27. a330b6cecb98: Already exists # 联合文件系统,已存在的不再重复下载
  28. 9c8f656c32b8: Already exists
  29. 88e473c3f553: Already exists
  30. 062463ea5d2f: Already exists
  31. daf7e3bdf4b6: Already exists
  32. 1839c0b7aac9: Already exists
  33. cf0a0cfee6d0: Already exists
  34. fae7a809788c: Pull complete # 下载不存在的
  35. dae5a82a61f0: Pull complete
  36. 7063da9569eb: Pull complete
  37. 51a9a9b4ef36: Pull complete
  38. Digest: sha256:d9b934cdf6826629f8d02ea01f28b2c4ddb1ae27c32664b14867324b3e5e1291
  39. Status: Downloaded newer image for mysql:5.7
  40. docker.io/library/mysql:5.7
  41. #查看
  42. docker images
  43. REPOSITORY TAG IMAGE ID CREATED SIZE
  44. mysql 5.7 1d7aba917169 3 weeks ago 448MB
  45. mysql latest 0716d6ebcc1a 3 weeks ago 514MB
  46. <none> <none> 95a86af3f2e7 4 months ago 570MB
  47. jenkins/jenkins latest ba8a0e5dc5cb 4 months ago 570MB
  48. nginx latest d1a364dc548d 4 months ago 133MB
  49. portainer/portainer latest 580c0e4e98b0 6 months ago 79.1MB
  50. hello-world latest d1165f221234 6 months ago 13.3kB

删除镜像

  1. docker rmi -f [镜像名、镜像ID]
  2. docker rmi -f 1d7aba917169
  3. Untagged: mysql:5.7
  4. Untagged: mysql@sha256:d9b934cdf6826629f8d02ea01f28b2c4ddb1ae27c32664b14867324b3e5e1291
  5. Deleted: sha256:1d7aba9171693947d53f474014821972bf25d72b7d143ce4af4c8d8484623417
  6. Deleted: sha256:94ebbead5c58282fef91cc7d0fb56e4006a72434b4a6ae2cd5be98f369cb8c21
  7. Deleted: sha256:989da5efad29ec59bd536cd393d277bc777f8b9b34b8e3ad9593a4b0a83b40f4
  8. Deleted: sha256:7457ee6817c678da3cb383d27a3d79d5f3f25fbcb92958d5e8d5709e7631e23c
  9. Deleted: sha256:fe7dac53adebe33519b4e4fc577bfcddd7372cc313c35fae681fc82fb325fdc0

容器命令

有了镜像才可以创建容器,下载centos镜像进行学习

  1. docker pull centos

新建容器并启动

  1. docker run [可选参数] imageName/imageId
  2. # 参数说明
  3. --name "NAME" 容器名字,tomcat01, tomcat02, 用来区分容器
  4. -d 后台方式运行
  5. -i , -t #使用交互模式运行,可以进入容器查看内容
  6. -p #指定容器端口 -p 8080
  7. -p ip:主机端口:容器端口 -p 3344:80
  8. -p 主机端口:容器端口 (常用)
  9. -p 容器端口
  10. 容器端口
  11. -P #随机指定端口

启动容器,并进入容器

  1. [root@iZm5e----- ~]# docker run -it centos /bin/bash
  2. [root@c4a1504a9cf9 /]# ls #查看容器内的centos
  3. bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
  4. [root@c4a1504a9cf9 /]# exit # 退出容器
  5. exit
  6. [root@iZm5e----- ~]#

image.png
CONTAINER ID c4a1504a9cf9

查看所有运行的容器

  1. docker ps #查看运行的容器 exit之后就停止了容器
  2. docker ps -a #查看所有运行过的以及在运行的容器
  3. docker ps -a
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  5. c4a1504a9cf9 centos "/bin/bash" 7 minutes ago Exited (0) 3 minutes ago hungry_euler
  6. dc0c5076048e hello-world "/hello" 2 months ago Exited (0) 2 months ago busy_cori
  7. docker ps -a -n=[数字] # 最近创建的容器
  8. docker ps -a -n=1
  9. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  10. c4a1504a9cf9 centos "/bin/bash" 11 minutes ago Exited (0) 7 minutes ago hungry_euler

退出容器

  1. exit #容器停止并退出
  2. ctrl + p + q #容器不停止退出

删除容器

  1. docker rm 容器ID # 删除指定容器 不能删除正在运行的容器
  2. docker rm -f $(docker ps -aq) # 递归删除所有容器
  3. docker ps -a -q|xargs docker rm # 删除所有容器

启动和停止容器

  1. docker start 容器ID # 启动容器
  2. docker restart 容器ID # 重启容器
  3. docker stop 容器ID # 停止当前正在运行的容器
  4. docker kill 容器ID # 强制停止当前容器

常用其它命令

后台运行容器

  1. docker run -d centos
  2. 463f1dc43e444ff6b6d0efd3f0c5047e118ddf64deed3aea2a8b5a6c89df61bb
  3. [root@iZm5e----- ~]# docker ps
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  5. [root@iZm5e----- ~]#

发现后台运行的容器,停止了
docker使用后台运行,就必须要有一个前台进程。否则,docker发现没有服务,就会自动停止

查看日志

  1. docker logs --help
  2. #shell脚本造日志
  3. docker run -d centos /bin/sh -c "while true;do echo xiao;sleep 1;done"
  4. d5033adf13b49f537430fc19df9fe00b477301dfd3a2d9c287060c65c1a59d7b
  5. [root@iZm5e----- ~]# docker ps
  6. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  7. d5033adf13b4 centos "/bin/sh -c 'while t…" 5 seconds ago Up 4 seconds competent_jang
  8. [root@iZm5e----- ~]#
  9. #显示日志
  10. docker logs -f -t --tail 10 d5033adf13b4
  11. 2021-09-27T07:05:08.800676670Z xiao
  12. 2021-09-27T07:05:09.803226803Z xiao
  13. 2021-09-27T07:05:10.806019019Z xiao
  14. 2021-09-27T07:05:11.809012200Z xiao
  15. 2021-09-27T07:05:12.811505073Z xiao
  16. 2021-09-27T07:05:13.817109532Z xiao
  17. 2021-09-27T07:05:14.819543508Z xiao
  18. 2021-09-27T07:05:15.822718210Z xiao
  19. ...
  20. -tf #显示日志
  21. --tail [数字] # 显示日志的条数

查看容器中的进程信息 (ps - linux)

docker top命令

  1. docker top 容器ID
  2. docker top d5033adf13b4
  3. UID PID PPID C STIME TTY TIME CMD
  4. root 29087 29069 0 15:01 ? 00:00:00 /bin/sh -c while true;do echo xiao;sleep 1;done
  5. root 29908 29087 0 15:08 ? 00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1
  6. [root@iZm5e----- ~]#

查看镜像的源数据

dockers inspect 命令
image.png

  1. docker inspect d5033adf13b4
  2. [
  3. {
  4. "Id": "d5033adf13b49f537430fc19df9fe00b477301dfd3a2d9c287060c65c1a59d7b",
  5. "Created": "2021-09-27T07:01:42.833109605Z",
  6. "Path": "/bin/sh",
  7. "Args": [
  8. "-c",
  9. "while true;do echo xiao;sleep 1;done"
  10. ],
  11. "State": {
  12. "Status": "running",
  13. "Running": true,
  14. "Paused": false,
  15. "Restarting": false,
  16. "OOMKilled": false,
  17. "Dead": false,
  18. "Pid": 29087,
  19. "ExitCode": 0,
  20. "Error": "",
  21. "StartedAt": "2021-09-27T07:01:43.288158158Z",
  22. "FinishedAt": "0001-01-01T00:00:00Z"
  23. },
  24. "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
  25. "ResolvConfPath": "/var/lib/docker/containers/d5033adf13b49f537430fc19df9fe00b477301dfd3a2d9c287060c65c1a59d7b/resolv.conf",
  26. "HostnamePath": "/var/lib/docker/containers/d5033adf13b49f537430fc19df9fe00b477301dfd3a2d9c287060c65c1a59d7b/hostname",
  27. "HostsPath": "/var/lib/docker/containers/d5033adf13b49f537430fc19df9fe00b477301dfd3a2d9c287060c65c1a59d7b/hosts",
  28. "LogPath": "/var/lib/docker/containers/d5033adf13b49f537430fc19df9fe00b477301dfd3a2d9c287060c65c1a59d7b/d5033adf13b49f537430fc19df9fe00b477301dfd3a2d9c287060c65c1a59d7b-json.log",
  29. "Name": "/competent_jang",
  30. "RestartCount": 0,
  31. "Driver": "overlay2",
  32. "Platform": "linux",
  33. "MountLabel": "",
  34. "ProcessLabel": "",
  35. "AppArmorProfile": "",
  36. "ExecIDs": null,
  37. "HostConfig": {
  38. "Binds": null,
  39. "ContainerIDFile": "",
  40. "LogConfig": {
  41. "Type": "json-file",
  42. "Config": {}
  43. },
  44. "NetworkMode": "default",
  45. "PortBindings": {},
  46. "RestartPolicy": {
  47. "Name": "no",
  48. "MaximumRetryCount": 0
  49. },
  50. "AutoRemove": false,
  51. "VolumeDriver": "",
  52. "VolumesFrom": null,
  53. "CapAdd": null,
  54. "CapDrop": null,
  55. "CgroupnsMode": "host",
  56. "Dns": [],
  57. "DnsOptions": [],
  58. "DnsSearch": [],
  59. "ExtraHosts": null,
  60. "GroupAdd": null,
  61. "IpcMode": "private",
  62. "Cgroup": "",
  63. "Links": null,
  64. "OomScoreAdj": 0,
  65. "PidMode": "",
  66. "Privileged": false,
  67. "PublishAllPorts": false,
  68. "ReadonlyRootfs": false,
  69. "SecurityOpt": null,
  70. "UTSMode": "",
  71. "UsernsMode": "",
  72. "ShmSize": 67108864,
  73. "Runtime": "runc",
  74. "ConsoleSize": [
  75. 0,
  76. 0
  77. ],
  78. "Isolation": "",
  79. "CpuShares": 0,
  80. "Memory": 0,
  81. "NanoCpus": 0,
  82. "CgroupParent": "",
  83. "BlkioWeight": 0,
  84. "BlkioWeightDevice": [],
  85. "BlkioDeviceReadBps": null,
  86. "BlkioDeviceWriteBps": null,
  87. "BlkioDeviceReadIOps": null,
  88. "BlkioDeviceWriteIOps": null,
  89. "CpuPeriod": 0,
  90. "CpuQuota": 0,
  91. "CpuRealtimePeriod": 0,
  92. "CpuRealtimeRuntime": 0,
  93. "CpusetCpus": "",
  94. "CpusetMems": "",
  95. "Devices": [],
  96. "DeviceCgroupRules": null,
  97. "DeviceRequests": null,
  98. "KernelMemory": 0,
  99. "KernelMemoryTCP": 0,
  100. "MemoryReservation": 0,
  101. "MemorySwap": 0,
  102. "MemorySwappiness": null,
  103. "OomKillDisable": false,
  104. "PidsLimit": null,
  105. "Ulimits": null,
  106. "CpuCount": 0,
  107. "CpuPercent": 0,
  108. "IOMaximumIOps": 0,
  109. "IOMaximumBandwidth": 0,
  110. "MaskedPaths": [
  111. "/proc/asound",
  112. "/proc/acpi",
  113. "/proc/kcore",
  114. "/proc/keys",
  115. "/proc/latency_stats",
  116. "/proc/timer_list",
  117. "/proc/timer_stats",
  118. "/proc/sched_debug",
  119. "/proc/scsi",
  120. "/sys/firmware"
  121. ],
  122. "ReadonlyPaths": [
  123. "/proc/bus",
  124. "/proc/fs",
  125. "/proc/irq",
  126. "/proc/sys",
  127. "/proc/sysrq-trigger"
  128. ]
  129. },
  130. "GraphDriver": {
  131. "Data": {
  132. "LowerDir": "/var/lib/docker/overlay2/9aec4e083e254075a863c62c5c54f7ad2d7321750b4384ff1e092e25c5dc257e-init/diff:/var/lib/docker/overlay2/d6e4be0166eac21b08ff7e34bb088bd7488086c5fd04603879424af35f8e6190/diff",
  133. "MergedDir": "/var/lib/docker/overlay2/9aec4e083e254075a863c62c5c54f7ad2d7321750b4384ff1e092e25c5dc257e/merged",
  134. "UpperDir": "/var/lib/docker/overlay2/9aec4e083e254075a863c62c5c54f7ad2d7321750b4384ff1e092e25c5dc257e/diff",
  135. "WorkDir": "/var/lib/docker/overlay2/9aec4e083e254075a863c62c5c54f7ad2d7321750b4384ff1e092e25c5dc257e/work"
  136. },
  137. "Name": "overlay2"
  138. },
  139. "Mounts": [],
  140. "Config": {
  141. "Hostname": "d5033adf13b4",
  142. "Domainname": "",
  143. "User": "",
  144. "AttachStdin": false,
  145. "AttachStdout": false,
  146. "AttachStderr": false,
  147. "Tty": false,
  148. "OpenStdin": false,
  149. "StdinOnce": false,
  150. "Env": [
  151. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  152. ],
  153. "Cmd": [
  154. "/bin/sh",
  155. "-c",
  156. "while true;do echo xiao;sleep 1;done"
  157. ],
  158. "Image": "centos",
  159. "Volumes": null,
  160. "WorkingDir": "",
  161. "Entrypoint": null,
  162. "OnBuild": null,
  163. "Labels": {
  164. "org.label-schema.build-date": "20210915",
  165. "org.label-schema.license": "GPLv2",
  166. "org.label-schema.name": "CentOS Base Image",
  167. "org.label-schema.schema-version": "1.0",
  168. "org.label-schema.vendor": "CentOS"
  169. }
  170. },
  171. "NetworkSettings": {
  172. "Bridge": "",
  173. "SandboxID": "182c5e5a4f65a8c8ae6fffc733ef2ff02b9c7ea0e374331017cb651077fb77c6",
  174. "HairpinMode": false,
  175. "LinkLocalIPv6Address": "",
  176. "LinkLocalIPv6PrefixLen": 0,
  177. "Ports": {},
  178. "SandboxKey": "/var/run/docker/netns/182c5e5a4f65",
  179. "SecondaryIPAddresses": null,
  180. "SecondaryIPv6Addresses": null,
  181. "EndpointID": "7dd5c90916bf7c472a88dc308498f198b59c9606c144c6d413b77ecc03e05cc1",
  182. "Gateway": "172.17.0.1",
  183. "GlobalIPv6Address": "",
  184. "GlobalIPv6PrefixLen": 0,
  185. "IPAddress": "172.17.0.2",
  186. "IPPrefixLen": 16,
  187. "IPv6Gateway": "",
  188. "MacAddress": "02:42:ac:11:00:02",
  189. "Networks": {
  190. "bridge": {
  191. "IPAMConfig": null,
  192. "Links": null,
  193. "Aliases": null,
  194. "NetworkID": "feafa30d4051f24353508959bd420fd163ad0c98d6b30ec8ff13b59a59552bb1",
  195. "EndpointID": "7dd5c90916bf7c472a88dc308498f198b59c9606c144c6d413b77ecc03e05cc1",
  196. "Gateway": "172.17.0.1",
  197. "IPAddress": "172.17.0.2",
  198. "IPPrefixLen": 16,
  199. "IPv6Gateway": "",
  200. "GlobalIPv6Address": "",
  201. "GlobalIPv6PrefixLen": 0,
  202. "MacAddress": "02:42:ac:11:00:02",
  203. "DriverOpts": null
  204. }
  205. }
  206. }
  207. }
  208. ]
  209. [root@iZm5e----- ~]#

进入当前正在运行的容器

1、docker exec -it 容器ID bashShell (常用)

  1. docker exec -it d5033adf13b4 /bin/bash
  2. [root@d5033adf13b4 /]# ls
  3. bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
  4. [root@d5033adf13b4 /]# ps -ef
  5. UID PID PPID C STIME TTY TIME CMD
  6. root 1 0 0 07:01 ? 00:00:00 /bin/sh -c while true;do echo xiao;sleep 1;done
  7. root 1895 0 0 07:33 pts/0 00:00:00 /bin/bash
  8. root 1937 1 0 07:33 ? 00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1
  9. root 1938 1895 0 07:33 pts/0 00:00:00 ps -ef
  10. [root@d5033adf13b4 /]#

2、docker attach 容器ID

  1. docker attach d5033adf13b4
  2. xiao
  3. xiao
  4. xiao
  5. xiao
  6. xiao
  7. ...

二者区别

docker exec # 进入容器后,开启一个新的终端,可以在里面操作
docker attach # 进入容器正在执行的终端,不会开启新的进程。

拷贝容器内文件到主机上

手动同步
docker cp 命令

  1. docker cp 容器ID:容器内路径 目的主机路径
  2. docker cp 2b7529b86ad0:/home/index.txt /home
  3. [root@iZm5e----- ~]# ls
  4. life mysql-community-release-el7-5.noarch.rpm study testSH work
  5. [root@iZm5e----- ~]# cd /home/
  6. [root@iZm5e----- home]# ls
  7. index.txt jenkins test
  8. [root@iZm5e----- home]#

image.png

问题探索

如何实现自动同步,打通容器和主机

查看cpu内存使用情况

docker stats
每秒刷新
image.png