Docker的安装与常用的命令

本文最后更新于:2021年9月19日 晚上

Docker 是一个开放源代码软件,是一个开放平台,用于开发应用、交付(shipping)应用、运行应用。 Docker允许用户将基础设施(Infrastructure)中的应用单独分割出来,形成更小的颗粒(容器),从而提高交付软件的速度。

安装 docker

准备环境

1、CentOS 7
2、使用 Xshell 连接远程服务器操作

环境查看

1
2
[root@bogon ~]# uname -r
3.10.0-1160.el7.x86_64 //系统内核是 3.10 以上

系统版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@bogon /]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

安装

根据官网提供的帮助文档操作:
1、卸载旧的版本

1
2
3
4
5
6
7
8
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

2、需要的安装包

1
yum install -y yum-utils

3、设置镜像的仓库

1
2
3
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo //官网提供的是国外的仓库速度比较慢
1
2
3
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo //我这里使用阿里云的,速度会快很多

更新 yum 软件包索引

1
yum makecache fast

4、 安装dokcer相关的 docker-ce 社区版 docker-ee 企业版

1
yum install docker-ce docker-ce-cli containerd.io

5、使用 docker version 查看 docker 版本信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@bogon /]# docker version
Client: Docker Engine - Community
Version: 20.10.8
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:55:49 2021
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:54:13 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0

6、启动 docker

1
systemctl start docker

查看 docker 版本

1
docker version

重启 docker

1
systemctl restart docker

关闭 docker

1
systemctl stop docker

7、hello-world

1
docker run hello-world
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@bogon chziyue]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:7d91b69e04a9029b99f3585aaaccae2baa80bcf318f4a5d2165a9898cd2dc0a1
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

8、查看下载的 hello-world 镜像

1
2
3
[root@bogon chziyue]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 6 months ago 13.3kB

卸载 docker

1、卸载依赖

1
yum remove docker-ce docker-ce-cli containerd.io

2、删除资源

1
2
rm -rf /var/lib/docker
rm -rf /var/lib/containerd

docker 的常用命令

帮助命令

1
2
3
docker version       //显示docker的版本信息
docker info //显示docker的系统信息,包括镜像和容器的数量
docker 命令 --help //帮助命令

帮助文档的地址:https://docs.docker.com/engine/reference/commandline/docker/

镜像命令

docker images 查看所有本地主机上的镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@bogon chziyue]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 6 months ago 13.3kB

//解释
REPOSITORY //镜像的仓库源
TAG //镜像的标签
IMAGE ID //镜像的id
CREATED //镜像的创建时间
SIZE //镜像的大小

//可选项
-a, --all //列出所有镜像
-q, --quiet //只显示镜像的id

docker search 搜索镜像

1
2
3
4
[root@bogon chziyue]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11409 [OK]
mariadb MariaDB Server is a high performing open sou… 4334 [OK]

可选项,通过搜藏来过滤 --filter==STARS=3000 搜索出来的镜像就是STARS大于3000的

1
2
3
4
5
6
7
[root@bogon chziyue]# docker search mysql --filter=stars=3000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11409 [OK]
mariadb MariaDB Server is a high performing open sou… 4334 [OK]
[root@bogon chziyue]# docker search mysql --filter=stars=5000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11409 [OK]

docker pull 下载镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//下载镜像 docker pull 镜像名[:tag]
[root@bogon chziyue]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
a330b6cecb98: Pull complete //分层下载,kocker iamge 的核心 联合文件系统
9c8f656c32b8: Pull complete
88e473c3f553: Pull complete
062463ea5d2f: Pull complete
daf7e3bdf4b6: Pull complete
1839c0b7aac9: Pull complete
cf0a0cfee6d0: Pull complete
1b42041bb11e: Pull complete
10459d86c7e6: Pull complete
b7199599d5f9: Pull complete
1d6f51e17d45: Pull complete
50e0789bacad: Pull complete
Digest: sha256:99e0989e7e3797cfbdb8d51a19d32c8d286dd8862794d01a547651a896bcf00c //签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest //真实地址

两条命令效果是一样的

1
2
docker pull mysql
docker pull docker.io/library/mysql:latest

指定版本下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@bogon chziyue]# docker pull mysql:5.7
5.7: Pulling from library/mysql
a330b6cecb98: Already exists
9c8f656c32b8: Already exists
88e473c3f553: Already exists
062463ea5d2f: Already exists
daf7e3bdf4b6: Already exists
1839c0b7aac9: Already exists
cf0a0cfee6d0: Already exists
fae7a809788c: Pull complete
dae5a82a61f0: Pull complete
7063da9569eb: Pull complete
51a9a9b4ef36: Pull complete
Digest: sha256:d9b934cdf6826629f8d02ea01f28b2c4ddb1ae27c32664b14867324b3e5e1291
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

查看下载的镜像

1
2
3
4
5
[root@bogon chziyue]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 1d7aba917169 10 days ago 448MB
mysql latest 0716d6ebcc1a 10 days ago 514MB
hello-world latest d1165f221234 6 months ago 13.3kB

docker rmi 删除镜像

1
2
3
[root@bogon chziyue]# docker rmi -f 镜像id                     //删除指定的镜像
[root@bogon chziyue]# docker rmi -f 镜像id 镜像id 镜像id 镜像id //删除多个镜像
[root@bogon chziyue]# docker rmi -f $(docker images -aq) //删除全部的镜像

容器命令

说明:有了镜像才可以创建容器,linux,下载一个 centos 镜像

1
docker pull centos

新建容器并启动

1
2
3
4
5
6
7
8
9
10
11
12
docker run [可选参数] image

//参数说明
--name="Name" 容器名字 tomcat01 tomcat02,用来区分容器
-d 后台方式运行
-it 使用交互方式运行,进入容器查看内容
-p 指定容器的端口 -p 8080:8080
-p ip:主机端口:容器端口
-p 主机端口:容器端口 (常用)
-p 容器端口
容器端口
-P 随机指定端口

测试,启动进入容器

1
2
3
[root@bogon chziyue]# docker run -it centos /bin/bash
[root@3000d155ddf7 /]# ls //查看容器内的目录
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var

从容器中退回主机

1
2
3
4
[root@3000d155ddf7 /]# exit
exit
[root@bogon /]# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

列出所有运行的容器

1
2
3
4
5
6
7
8
9
10
11
docker ps     //列出当前正在运行的容器
-a //列出当前正在运行的容器+历史运行过的容器
-n=? //显示最近创建的容器
-q //只显示容器的编号

[root@bogon /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@bogon /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3000d155ddf7 centos "/bin/bash" 3 minutes ago Exited (0) About a minute ago kind_mccarthy
005725a350d3 d1165f221234 "/hello" About an hour ago Exited (0) About an hour ago practical_ritchie

退出容器

1
2
exit    //容器停止并退出
Ctrl + P + Q //容器不停止退出

删除容器

1
2
3
docker rm 容器id                 //删除指定的容器,不能删除正在运行的容器,如果要强制删除 rm -f
docker rm -f $(docker ps -aq) //删除所有的容器
docker ps -a -q|xargs docker rm //删除所有的容器

启动和停止容器的操作

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

常用的其他命令

后台启动容器

1
2
3
4
5
6
//docker run -d 镜像名
[root@bogon /]# docker run -d centos

//docker ps, 发现 centos 停止了
//说明:docker 容器使用后台运行,必须要有一个前台进程,docker发现没有应用,就会自动停止
//nginx 容器启动后,发现自己没有提供服务,就会立刻停止

查看日志

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
docker logs -tf --tail 容器

//编写一段 shell 脚本来产生日志
//创建一个 while 循环,每隔1秒输出一句 Hello
//启动并执行 shell 脚本
[root@bogon /]# docker run -d centos /bin/sh -c "while true;do echo Hello;sleep 1;done"
30b9e1d3e0e154e206cb8820c344e19f4cbb0020d147f3a9d35db5659f488362

//查看运行中的镜像
[root@bogon /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
30b9e1d3e0e1 centos "/bin/sh -c 'while t…" 5 seconds ago Up 4 seconds bold_jemison

//显示日志
-tf //显示日志
--tail number //要显示日志的条数
[root@bogon /]# docker logs -tf --tail 10 30b9e1d3e0e1
2021-09-13T13:38:15.454797542Z Hello
2021-09-13T13:38:16.460296968Z Hello
2021-09-13T13:38:17.465308111Z Hello
2021-09-13T13:38:18.471366290Z Hello
2021-09-13T13:38:19.475148265Z Hello
2021-09-13T13:38:20.478896705Z Hello
2021-09-13T13:38:21.485814153Z Hello
2021-09-13T13:38:22.489167933Z Hello
2021-09-13T13:38:23.492039723Z Hello
2021-09-13T13:38:24.498429851Z Hello

查看容器中进程信息

1
2
3
4
5
//docker top 容器id
[root@bogon /]# docker top 30b9e1d3e0e1
UID PID PPID C STIME TTY TIME CMD
root 5226 5207 0 21:37 ? 00:00:00 /bin/sh -c while true;do echo Hello;sleep 1;done
root 6036 5226 0 21:47 ? 00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1

查看镜像的元数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//docker inspect 容器id

//测试
[root@bogon /]# docker inspect 30b9e1d3e0e1
[
{
"Id": "30b9e1d3e0e154e206cb8820c344e19f4cbb0020d147f3a9d35db5659f488362",
"Created": "2021-09-13T13:37:02.838337914Z",
"Path": "/bin/sh",
"Args": [
"-c",
"while true;do echo Hello;sleep 1;done"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 5226,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-09-13T13:37:03.113992667Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55",
"ResolvConfPath": "/var/lib/docker/containers/30b9e1d3e0e154e206cb8820c344e19f4cbb0020d147f3a9d35db5659f488362/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/30b9e1d3e0e154e206cb8820c344e19f4cbb0020d147f3a9d35db5659f488362/hostname",
"HostsPath": "/var/lib/docker/containers/30b9e1d3e0e154e206cb8820c344e19f4cbb0020d147f3a9d35db5659f488362/hosts",
"LogPath": "/var/lib/docker/containers/30b9e1d3e0e154e206cb8820c344e19f4cbb0020d147f3a9d35db5659f488362/30b9e1d3e0e154e206cb8820c344e19f4cbb0020d147f3a9d35db5659f488362-json.log",
"Name": "/bold_jemison",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/f48ed78571e899feb1e6ef75274effd5898f67e1f03ce2707b6139b024a15b90-init/diff:/var/lib/docker/overlay2/02dacaffc64f4460948b0da3bfc99ae662a954517bdf99a022ddba4252daaeb1/diff",
"MergedDir": "/var/lib/docker/overlay2/f48ed78571e899feb1e6ef75274effd5898f67e1f03ce2707b6139b024a15b90/merged",
"UpperDir": "/var/lib/docker/overlay2/f48ed78571e899feb1e6ef75274effd5898f67e1f03ce2707b6139b024a15b90/diff",
"WorkDir": "/var/lib/docker/overlay2/f48ed78571e899feb1e6ef75274effd5898f67e1f03ce2707b6139b024a15b90/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "30b9e1d3e0e1",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"while true;do echo Hello;sleep 1;done"
],
"Image": "centos",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20201204",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "ce8566838ea1d35d1dcf361ad753f5bb0ee30d1620fbebb2472295d1bbebb1d0",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/ce8566838ea1",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "92a040160498a98fdc9fac4194cd8f8fce42c92269bb5a0bb207333c21593ed6",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "baf930fbe322744c4b381bb941632068493b359bbd6ae45b320785ed5b471c90",
"EndpointID": "92a040160498a98fdc9fac4194cd8f8fce42c92269bb5a0bb207333c21593ed6",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]

进入当前正在运行的容器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//通常容器都是使用后台方式运行的,需要进入容器,修改一些配置

//命令
docker exec -it 容器id bashShell

//测试
[root@bogon /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
30b9e1d3e0e1 centos "/bin/sh -c 'while t…" 20 minutes ago Up 20 minutes bold_jemison
[root@bogon /]# docker exec -it 30b9e1d3e0e1 /bin/bash
[root@30b9e1d3e0e1 /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@30b9e1d3e0e1 /]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 13:37 ? 00:00:00 /bin/sh -c while true;do echo Hello;sleep 1;done
root 1229 0 0 13:57 pts/0 00:00:00 /bin/bash
root 1253 1 0 13:57 ? 00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1
root 1254 1229 0 13:57 pts/0 00:00:00 ps -ef


//方式二
docker attach 容器id
//测试
[root@30b9e1d3e0e1 /]# docker attach 30b9e1d3e0e1

docker exec //进入容器后开启一个新的终端,可以在里面操作(常用)
docker attach //进入容器正在执行的终端,不会启动新的进程

从容器内拷贝文件到主机上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
docker cp 容器id:容器内路径 目的地主机路径

//查看当前主机 home 目录
[root@bogon home]# ls
chziyue

//进入容器内部
[root@bogon home]# docker attach c8f6c548a9f8
[root@c8f6c548a9f8 /]# cd /home
[root@c8f6c548a9f8 home]# ls

//在容器内新建 index.html 文件
[root@c8f6c548a9f8 home]# touch index.html
[root@c8f6c548a9f8 home]# ls
index.html

//退出容器
[root@c8f6c548a9f8 home]# exit
exit
[root@bogon home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@bogon home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8f6c548a9f8 centos "/bin/bash" 3 minutes ago Exited (0) 10 seconds ago stupefied_buck

//将 index.html 拷贝出来到主机上
[root@bogon home]# docker cp c8f6c548a9f8:/home/index.html /home
[root@bogon home]# ls
chziyue index.html

//拷贝是一个手动过程,未来还可以使用 -v 卷的技术,实现文件自动同步

本博客所有文章仅供学习和交流所用,未经作者允许,均禁止转载!