# 常用命令小结(结果先行):
1、镜像命令
docker images:查看所有本地的主机上的镜像
docker search :搜索镜像,跟docker hub 上搜索结果一样
docker pull : 下载镜像
docker rmi 镜像id:删除镜像
2、容器命令
docker run -it 镜像名称 /bin/bash :通过镜像创建容器并启动容器
docker ps 可选参数 #查看运行的容器
docker rm 容器id :删除指定的容器,运行中的容器删除不了,需要-f ,docker rm -f 容器id
docker rm -f $(docker ps -aq) :删除所有的容器
docker start 容器id # 启动容器
docker restart 容器id # 重启容器
docker stop 容器id # 停止当前正在运行的容器
docker kill 容器id # 强制停止当前容器
docker top 容器id # 查看容器中进程信息:pid:当前进程id,ppid:父进程id
docker inspect 容器id|容器名:版本号 # 查看容器的元数据
docker exec -it 容器id /bin/bash # 进入当前正在运行的容器
docker cp 容器id:文件路径 主机存放路径 # 从容器内拷贝文件到主机上
3、帮助命令
docker version # 显示docker的版本信息
docker info # 显示docker的系统信息,包括镜像和容器的数量
docker 命令 --help # 帮助命令
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
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
# 查看容器的元数据
docker inspect 容器ID
在Docker中,一个很重要的概念就是
GraphDriver
,它主要用于管理和维护镜像,包括把镜像从仓库下载下来,到运行时把镜像挂载起来可以被容器访问等,都是GraphDriver
去完成的。
[root@iZbp1dg7mun11n29b6ndm6Z ~]# docker inspect rabbitmq
[
{
"Id": "75c688fade05cf116c219c98a3291681b31bd594bdee9e20ca4356de2be49d54",
"Created": "2023-01-29T08:19:31.81602453Z",
"Path": "docker-entrypoint.sh",
"Args": [
"rabbitmq-server"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 29543,
"ExitCode": 0,
"Error": "",
"StartedAt": "2023-01-30T06:22:19.848560278Z",
"FinishedAt": "2023-01-30T06:22:14.562177701Z"
},
"Image": "sha256:d445c0adc9a5596c50e5b73b8b636f79de24ad9da00671714aea768b3fa4ee9b",
"ResolvConfPath": "/var/lib/docker/containers/75c688fade05cf116c219c98a3291681b31bd594bdee9e20ca4356de2be49d54/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/75c688fade05cf116c219c98a3291681b31bd594bdee9e20ca4356de2be49d54/hostname",
"HostsPath": "/var/lib/docker/containers/75c688fade05cf116c219c98a3291681b31bd594bdee9e20ca4356de2be49d54/hosts",
"LogPath": "/var/lib/docker/containers/75c688fade05cf116c219c98a3291681b31bd594bdee9e20ca4356de2be49d54/75c688fade05cf116c219c98a3291681b31bd594bdee9e20ca4356de2be49d54-json.log",
"Name": "/rabbitmq",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"15672/tcp": [
{
"HostIp": "",
"HostPort": "15672"
}
],
"5672/tcp": [
{
"HostIp": "",
"HostPort": "5672"
}
]
},
"RestartPolicy": {
"Name": "always",
"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/346e18c0e8e1bc04f3be2d7c848dbedd25ddd63639ff41ce6e19c8936e711db6-init/diff:/var/lib/docker/overlay2/d1f57dc40a37ea144eda52008ce77c6a204315fd463503ebb44d738f9def02d6/diff:/var/lib/docker/overlay2/94e59be20d43ea92c6db5d340e4e487aa48173f4c437ac301cf3020231ef53df/diff:/var/lib/docker/overlay2/91ebb4d307f75386fbfa2c870770cebba9f9cec0e88c3204758386bd7231b0f9/diff:/var/lib/docker/overlay2/26ae282efeabcfc1e1b0b487a2550d7ca1504048e58fd6a244835b9616b9b3af/diff:/var/lib/docker/overlay2/55d42966a32b217c6b97ac2b04fe56a8b1434538c78abda79a1fe01cef7d7570/diff:/var/lib/docker/overlay2/b37a30724d2e5cda683b3646dfdaa589661da410e29331fd5d0396eb9a5aaa29/diff:/var/lib/docker/overlay2/487d3efd72670cb9762b0d7abc407f152f5bf39a5777cf353fc325bd79acbf19/diff:/var/lib/docker/overlay2/9bbf703d2ce4a6d1d78cc443297250cca265a1a1204620eabe104358372b5e4a/diff:/var/lib/docker/overlay2/925b67bb37abd8a6d62c5188e66f0bd28d308d10274e13ccf88bb9d1449a1fb6/diff",
"MergedDir": "/var/lib/docker/overlay2/346e18c0e8e1bc04f3be2d7c848dbedd25ddd63639ff41ce6e19c8936e711db6/merged",
"UpperDir": "/var/lib/docker/overlay2/346e18c0e8e1bc04f3be2d7c848dbedd25ddd63639ff41ce6e19c8936e711db6/diff",
"WorkDir": "/var/lib/docker/overlay2/346e18c0e8e1bc04f3be2d7c848dbedd25ddd63639ff41ce6e19c8936e711db6/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "volume",
"Name": "ad29726ea314115baebd50cab42b12676e5074dd90b48a4a87dcda7be5da7849",
"Source": "/var/lib/docker/volumes/ad29726ea314115baebd50cab42b12676e5074dd90b48a4a87dcda7be5da7849/_data",
"Destination": "/var/lib/rabbitmq",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "rabbitmq",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"15672/tcp": {},
"15691/tcp": {},
"15692/tcp": {},
"25672/tcp": {},
"4369/tcp": {},
"5671/tcp": {},
"5672/tcp": {}
},
"Tty": false,
"OpenStdin": true,
"StdinOnce": false,
"Env": [
"PATH=/opt/rabbitmq/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"OPENSSL_VERSION=1.1.1m",
"OPENSSL_SOURCE_SHA256=f89199be8b23ca45fc7cb9f1d8d3ee67312318286ad030f5316aca6462db6c96",
"OPENSSL_PGP_KEY_IDS=0x8657ABB260F056B1E5190839D9C4D26D0E604491 0x5B2545DAB21995F4088CEFAA36CEE4DEB00CFE33 0xED230BEC4D4F2518B9D7DF41F0DB4D21C1D35231 0xC1F33DD8CE1D4CC613AF14DA9195C48241FBF7DD 0x7953AC1FBC3DC8B3B292393ED5E9E43F7DF9EE8C 0xE5E52560DD91C556DDBDA5D02064C53641C25E5D",
"OTP_VERSION=24.2",
"OTP_SOURCE_SHA256=af0f1928dcd16cd5746feeca8325811865578bf1a110a443d353ea3e509e6d41",
"RABBITMQ_DATA_DIR=/var/lib/rabbitmq",
"RABBITMQ_VERSION=3.9.11",
"RABBITMQ_PGP_KEY_ID=0x0A9AF2115F4687BD29803A206B73A36E6026DFCA",
"RABBITMQ_HOME=/opt/rabbitmq",
"RABBITMQ_LOGS=-",
"HOME=/var/lib/rabbitmq",
"LANG=C.UTF-8",
"LANGUAGE=C.UTF-8",
"LC_ALL=C.UTF-8"
],
"Cmd": [
"rabbitmq-server"
],
"Image": "rabbitmq",
"Volumes": {
"/var/lib/rabbitmq": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "58608bd980cd569828f65ee1dbb3d86ece25313520d0a13b4d713c2207056d2b",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"15672/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "15672"
},
{
"HostIp": "::",
"HostPort": "15672"
}
],
"15691/tcp": null,
"15692/tcp": null,
"25672/tcp": null,
"4369/tcp": null,
"5671/tcp": null,
"5672/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "5672"
},
{
"HostIp": "::",
"HostPort": "5672"
}
]
},
"SandboxKey": "/var/run/docker/netns/58608bd980cd",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "6129ccc527280178c4be39392eae262820f3dde58bb79080292ff4e4d8df2ef3",
"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": "de078644f985fd6525e1562f58f81aa149f6e8d6fc2ed67fa648493e078e41b1",
"EndpointID": "6129ccc527280178c4be39392eae262820f3dde58bb79080292ff4e4d8df2ef3",
"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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
可以看到容器的元数据特别的多,这里我们使用grep
命令来检索GraphDriver(图形驱动程序)
,只展示8行主要信息
docker inspect rabbitmq | grep GraphDriver -A 8
1
[root@iZbp1dg7mun11n29b6ndm6Z ~]# docker inspect rabbitmq | grep GraphDriver -A 8
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/346e18c0e8e1bc04f3be2d7c848dbedd25ddd63639ff41ce6e19c8936e711db6-init/diff:/var/lib/docker/overlay2/d1f57dc40a37ea144eda52008ce77c6a204315fd463503ebb44d738f9def02d6/diff:/var/lib/docker/overlay2/94e59be20d43ea92c6db5d340e4e487aa48173f4c437ac301cf3020231ef53df/diff:/var/lib/docker/overlay2/91ebb4d307f75386fbfa2c870770cebba9f9cec0e88c3204758386bd7231b0f9/diff:/var/lib/docker/overlay2/26ae282efeabcfc1e1b0b487a2550d7ca1504048e58fd6a244835b9616b9b3af/diff:/var/lib/docker/overlay2/55d42966a32b217c6b97ac2b04fe56a8b1434538c78abda79a1fe01cef7d7570/diff:/var/lib/docker/overlay2/b37a30724d2e5cda683b3646dfdaa589661da410e29331fd5d0396eb9a5aaa29/diff:/var/lib/docker/overlay2/487d3efd72670cb9762b0d7abc407f152f5bf39a5777cf353fc325bd79acbf19/diff:/var/lib/docker/overlay2/9bbf703d2ce4a6d1d78cc443297250cca265a1a1204620eabe104358372b5e4a/diff:/var/lib/docker/overlay2/925b67bb37abd8a6d62c5188e66f0bd28d308d10274e13ccf88bb9d1449a1fb6/diff",
"MergedDir": "/var/lib/docker/overlay2/346e18c0e8e1bc04f3be2d7c848dbedd25ddd63639ff41ce6e19c8936e711db6/merged",
"UpperDir": "/var/lib/docker/overlay2/346e18c0e8e1bc04f3be2d7c848dbedd25ddd63639ff41ce6e19c8936e711db6/diff",
"WorkDir": "/var/lib/docker/overlay2/346e18c0e8e1bc04f3be2d7c848dbedd25ddd63639ff41ce6e19c8936e711db6/work"
},
"Name": "overlay2"
},
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
通过查看容器详情的GraphDriver.Data,我们可以知道有下面几个重要目录
- LowerDir:image 镜像层(镜像本身,只读)
- UpperDir:容器的上层(读写)
- MergedDir:容器的文件系统,使用Union FS(联合文件系统)将lowerdir 和upperdir 合并给容器使用
- WorkDir:容器在 宿主机的工作目录
https://blog.csdn.net/qq_31762741/article/details/128818772
/usr/local/node-14/node-v14.15.1-linux-x64/
node: /usr/bin/node /usr/local/bin/node /usr/share/node /usr/share/man/man1/node.1.gz