在安装之前,我们先了解什么是Docker
什么是Docker?
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows操作系统的机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
1、Docker是基于Go语言实现的云开源项目。
2、Docker的主要目标是,“Build,Ship and Run Any App,Anywhere”,也就是通过对应用组件的封装、分发、部署、运行等生命周期的管理,使用户的App(可以是一个Web应用或数据库应用等)及其运行环境能够做到“一次封装,到处运行”。
Docke能干什么?
传统虚拟技术,比如VMware,它是虚拟出一套硬件后,在其上运行一个完整操作系统,在该系统上再运行所需应用进程。【可以看出,虚拟机需要的内存大,而且配置麻烦】
而容器内的应用进程直接运行于宿主的内核,容器没有自己的内核,而且没有进行硬件模拟,因此,容器要比传统虚拟机更轻便。
每个容器之间互相隔离,每个容器有自己的文件系统,容器之间进程不会互相影响,能区分计算资源。
Docker主要的思想就是来自于集装箱,Docker采用隔离机制,对每个应用进行打包装箱,每个箱子都是互相隔离订单,可以理解为是一个个的镜像,镜像内部附带有运行环境。
容器化技术并不是模拟的一个完整的操作系统
Docker三要素
镜像(image):docker镜像就好比一个模板,可以通过这个模板来创建容器服务
容器(container): docker利用容器技术,独立运行一个或者一组应用,通过镜像来创建
**仓库(repository):**仓库,顾名思义,就是存放镜像的地方,其中,仓库分公有仓库和私有仓库
CentOS8安装Docker
首先查看内核
- uname - r
uname 用于打印当前系统相关信息,如内核版本号、硬件架构、主机名称和操作系统类型等】
1
24.18.0-80.el8.x86_64
查看内核信息
- cat /etc/os-release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16NAME="CentOS Linux" VERSION="8 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-8" CENTOS_MANTISBT_PROJECT_VERSION="8" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="8"
使用Docker仓库进行安装
Docker分为社区版ce和企业版ee,我们选择社区版
第一,先查看是否存在Podman,如果有,就先删除
不删除的话,会与Docker的安装包有如下的冲突:
1
2
3
4- 软件包 containerd.io-1.4.9-3.1.el8.x86_64 与 runc(由 runc-1.0.1-3.module_el8.5.0+870+f792de72.x86_64 提供)冲突 - 软件包 containerd.io-1.4.9-3.1.el8.x86_64 取代了 runc(由 runc-1.0.1-3.module_el8.5.0+870+f792de72.x86_64 提供) - 软件包 containerd.io-1.4.9-3.1.el8.x86_64 与 runc(由 runc-1.0.1-5.module_el8.5.0+878+851f435b.x86_64 提供)冲突
查看是否存在Podman
1
2
3[root@localhost yum.repos.d]# rpm -q podman podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64
删除Podman
1
2yum erase podman buildah
一路选择y即可
第二步,安装需要的软件包:yum-utils、device-mapper-persistent-data和lvm2
1
2
3
4yum install -y yum-utils device-mapper-persistent-data lvm2
详情如下:
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
57Repository AppStream is listed more than once in the configuration Repository extras is listed more than once in the configuration Repository PowerTools is listed more than once in the configuration Repository centosplus is listed more than once in the configuration CentOS-8-stream - AppStream - mirrors.aliyun.com 8.2 kB/s | 4.4 kB 00:00 CentOS-8-stream - AppStream - mirrors.aliyun.com 659 kB/s | 22 MB 00:34 CentOS-8-stream - Base - mir [ === ] --- B/s | 0 B --:-- ETA CentOS-8-stream - Base - mirrors.aliyun.com 9.9 kB/s | 3.9 kB 00:00 CentOS-8-stream - Base - mirrors.aliyun.com 919 kB/s | 22 MB 00:24 CentOS-8-stream - Extras - mirrors.aliyun.com 10 kB/s | 2.9 kB 00:00 Docker CE Stable - x86_64 13 kB/s | 3.5 kB 00:00 Docker CE Stable - x86_64 35 kB/s | 25 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 6.5 kB/s | 10 kB 00:01 Extra Packages for Enterprise Linux 8 - x86_64 1.8 MB/s | 11 MB 00:06 Extra Packages for Enterprise Linux Modular 8 - x86_64 7.0 kB/s | 9.8 kB 00:01 Extra Packages for Enterprise Linux Modular 8 - x86_64 456 kB/s | 1.0 MB 00:02 软件包 yum-utils-4.0.21-11.el8.noarch 已安装。 软件包 device-mapper-persistent-data-0.9.0-6.el8.x86_64 已安装。 软件包 lvm2-8:2.03.14-3.el8.x86_64 已安装。 依赖关系解决。 无需任何处理。 完毕!
第三步,设置国内下载镜像,例如阿里云仓库
1
2
3
4
5
6
7
8
9yum-config-manager --add-repo #这个是默认的仓库 https://download.docker.com/linux/centos/docker-ce.repo yum-config-manager --add-repo #设置阿里云仓库 http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
结果如下:
1
2
3
4
5
6Repository AppStream is listed more than once in the configuration Repository extras is listed more than once in the configuration Repository PowerTools is listed more than once in the configuration Repository centosplus is listed more than once in the configuration 添加仓库自:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
第四步:安装docker engine,包括docker-ce、docker-ce-cli和containerd.io
1
2yum install docker-ce docker-ce-cli containerd.io
结果如下:
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404Repository AppStream is listed more than once in the configuration Repository extras is listed more than once in the configuration Repository PowerTools is listed more than once in the configuration Repository centosplus is listed more than once in the configuration 上次元数据过期检查:0:01:35 前,执行于 2022年05月22日 星期日 09时24分18秒。 依赖关系解决。 ================================================================================================ 软件包 架构 版本 仓库 大小 ================================================================================================ 安装: containerd.io x86_64 1.6.4-3.1.el8 docker-ce-stable 33 M docker-ce x86_64 3:20.10.16-3.el8 docker-ce-stable 22 M docker-ce-cli x86_64 1:20.10.16-3.el8 docker-ce-stable 29 M 升级: libsemanage x86_64 2.9-8.el8 base 168 k policycoreutils x86_64 2.9-19.el8 base 374 k policycoreutils-python-utils noarch 2.9-19.el8 base 253 k python3-libsemanage x86_64 2.9-8.el8 base 128 k python3-policycoreutils noarch 2.9-19.el8 base 2.2 M selinux-policy noarch 3.14.3-98.el8 base 647 k selinux-policy-targeted noarch 3.14.3-98.el8 base 15 M 安装依赖关系: container-selinux noarch 2:2.180.0-1.module_el8.7.0+1106+45480ee0 AppStream 59 k docker-ce-rootless-extras x86_64 20.10.16-3.el8 docker-ce-stable 4.7 M fuse-overlayfs x86_64 1.8.2-1.module_el8.7.0+1106+45480ee0 AppStream 73 k fuse3 x86_64 3.2.1-12.el8 base 50 k fuse3-libs x86_64 3.3.0-15.el8 base 95 k libcgroup x86_64 0.41-19.el8 base 70 k libslirp x86_64 4.4.0-1.module_el8.6.0+926+8bef8ae7 AppStream 70 k slirp4netns x86_64 1.1.8-2.module_el8.7.0+1106+45480ee0 AppStream 51 k 安装弱的依赖: docker-scan-plugin x86_64 0.17.0-3.el8 docker-ce-stable 3.8 M 事务概要 ================================================================================================ 安装 12 软件包 升级 7 软件包 总下载:112 M 确定吗?[y/N]: y 下载软件包: (1/19): fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86 156 kB/s | 73 kB 00:00 (2/19): container-selinux-2.180.0-1.module_el8.7.0+1106+45480ee 122 kB/s | 59 kB 00:00 (3/19): libslirp-4.4.0-1.module_el8.6.0+926+8bef8ae7.x86_64.rpm 139 kB/s | 70 kB 00:00 (4/19): slirp4netns-1.1.8-2.module_el8.7.0+1106+45480ee0.x86_64 266 kB/s | 51 kB 00:00 (5/19): fuse3-3.2.1-12.el8.x86_64.rpm 259 kB/s | 50 kB 00:00 (6/19): fuse3-libs-3.3.0-15.el8.x86_64.rpm 325 kB/s | 95 kB 00:00 (7/19): libcgroup-0.41-19.el8.x86_64.rpm 225 kB/s | 70 kB 00:00 (8/19): docker-ce-20.10.16-3.el8.x86_64.rpm 947 kB/s | 22 MB 00:23 (9/19): docker-ce-rootless-extras-20.10.16-3.el8.x86_64.rpm 870 kB/s | 4.7 MB 00:05 (10/19): docker-ce-cli-20.10.16-3.el8.x86_64.rpm 1.0 MB/s | 29 MB 00:30 (11/19): libsemanage-2.9-8.el8.x86_64.rpm 382 kB/s | 168 kB 00:00 (12/19): policycoreutils-2.9-19.el8.x86_64.rpm 555 kB/s | 374 kB 00:00 (13/19): policycoreutils-python-utils-2.9-19.el8.noarch.rpm 532 kB/s | 253 kB 00:00 (14/19): python3-libsemanage-2.9-8.el8.x86_64.rpm 385 kB/s | 128 kB 00:00 (15/19): docker-scan-plugin-0.17.0-3.el8.x86_64.rpm 1.1 MB/s | 3.8 MB 00:03 (16/19): selinux-policy-3.14.3-98.el8.noarch.rpm 541 kB/s | 647 kB 00:01 (17/19): python3-policycoreutils-2.9-19.el8.noarch.rpm 608 kB/s | 2.2 MB 00:03 (18/19): containerd.io-1.6.4-3.1.el8.x86_64.rpm 899 kB/s | 33 MB 00:37 (19/19): selinux-policy-targeted-3.14.3-98.el8.noarch.rpm 601 kB/s | 15 MB 00:25 ------------------------------------------------------------------------------------------------ 总计 1.9 MB/s | 112 MB 01:00 Docker CE Stable - x86_64 1.3 kB/s | 1.6 kB 00:01 导入 GPG 公钥 0x621E9F35: Userid: "Docker Release (CE rpm) <docker@docker.com>" 指纹: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35 来自: https://download.docker.com/linux/centos/gpg 确定吗?[y/N]: y 导入公钥成功 运行事务检查 事务检查成功。 运行事务测试 事务测试成功。 运行事务 准备中 : 1/1 运行脚本: docker-scan-plugin-0.17.0-3.el8.x86_64 1/1 安装 : docker-scan-plugin-0.17.0-3.el8.x86_64 1/26 运行脚本: docker-scan-plugin-0.17.0-3.el8.x86_64 1/26 安装 : docker-ce-cli-1:20.10.16-3.el8.x86_64 2/26 运行脚本: docker-ce-cli-1:20.10.16-3.el8.x86_64 2/26 升级 : libsemanage-2.9-8.el8.x86_64 3/26 升级 : policycoreutils-2.9-19.el8.x86_64 4/26 运行脚本: policycoreutils-2.9-19.el8.x86_64 4/26 升级 : selinux-policy-3.14.3-98.el8.noarch 5/26 运行脚本: selinux-policy-3.14.3-98.el8.noarch 5/26 运行脚本: selinux-policy-targeted-3.14.3-98.el8.noarch 6/26 升级 : selinux-policy-targeted-3.14.3-98.el8.noarch 6/26 运行脚本: selinux-policy-targeted-3.14.3-98.el8.noarch 6/26 ^A^H^H^H 升级 : python3-libsemanage-2.9-8.el8.x86_64 7/26 升级 : python3-policycoreutils-2.9-19.el8.noarch 8/26 升级 : policycoreutils-python-utils-2.9-19.el8.noarch 9/26 运行脚本: container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch 10/26 安装 : container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch 10/26 运行脚本: container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch 10/26 安装 : containerd.io-1.6.4-3.1.el8.x86_64 11/26 运行脚本: containerd.io-1.6.4-3.1.el8.x86_64 11/26 运行脚本: libcgroup-0.41-19.el8.x86_64 12/26 安装 : libcgroup-0.41-19.el8.x86_64 12/26 运行脚本: libcgroup-0.41-19.el8.x86_64 12/26 安装 : fuse3-libs-3.3.0-15.el8.x86_64 13/26 运行脚本: fuse3-libs-3.3.0-15.el8.x86_64 13/26 安装 : fuse3-3.2.1-12.el8.x86_64 14/26 安装 : fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86_64 15/26 运行脚本: fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86_64 15/26 安装 : libslirp-4.4.0-1.module_el8.6.0+926+8bef8ae7.x86_64 16/26 安装 : slirp4netns-1.1.8-2.module_el8.7.0+1106+45480ee0.x86_64 17/26 安装 : docker-ce-rootless-extras-20.10.16-3.el8.x86_64 18/26 运行脚本: docker-ce-rootless-extras-20.10.16-3.el8.x86_64 18/26 安装 : docker-ce-3:20.10.16-3.el8.x86_64 19/26 运行脚本: docker-ce-3:20.10.16-3.el8.x86_64 19/26 清理 : selinux-policy-targeted-3.14.1-61.el8.noarch 20/26 运行脚本: selinux-policy-targeted-3.14.1-61.el8.noarch 20/26 清理 : selinux-policy-3.14.1-61.el8.noarch 21/26 运行脚本: selinux-policy-3.14.1-61.el8.noarch 21/26 清理 : policycoreutils-python-utils-2.8-16.1.el8.noarch 22/26 清理 : python3-policycoreutils-2.8-16.1.el8.noarch 23/26 清理 : python3-libsemanage-2.8-5.el8.x86_64 24/26 运行脚本: policycoreutils-2.8-16.1.el8.x86_64 25/26 清理 : policycoreutils-2.8-16.1.el8.x86_64 25/26 清理 : libsemanage-2.8-5.el8.x86_64 26/26 运行脚本: container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch 26/26 运行脚本: libsemanage-2.8-5.el8.x86_64 26/26 验证 : container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch 1/26 验证 : fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86_64 2/26 验证 : libslirp-4.4.0-1.module_el8.6.0+926+8bef8ae7.x86_64 3/26 验证 : slirp4netns-1.1.8-2.module_el8.7.0+1106+45480ee0.x86_64 4/26 验证 : fuse3-3.2.1-12.el8.x86_64 5/26 验证 : fuse3-libs-3.3.0-15.el8.x86_64 6/26 验证 : libcgroup-0.41-19.el8.x86_64 7/26 验证 : containerd.io-1.6.4-3.1.el8.x86_64 8/26 验证 : docker-ce-3:20.10.16-3.el8.x86_64 9/26 验证 : docker-ce-cli-1:20.10.16-3.el8.x86_64 10/26 验证 : docker-ce-rootless-extras-20.10.16-3.el8.x86_64 11/26 验证 : docker-scan-plugin-0.17.0-3.el8.x86_64 12/26 验证 : libsemanage-2.9-8.el8.x86_64 13/26 验证 : libsemanage-2.8-5.el8.x86_64 14/26 验证 : policycoreutils-2.9-19.el8.x86_64 15/26 验证 : policycoreutils-2.8-16.1.el8.x86_64 16/26 验证 : policycoreutils-python-utils-2.9-19.el8.noarch 17/26 验证 : policycoreutils-python-utils-2.8-16.1.el8.noarch 18/26 验证 : python3-libsemanage-2.9-8.el8.x86_64 19/26 验证 : python3-libsemanage-2.8-5.el8.x86_64 20/26 验证 : python3-policycoreutils-2.9-19.el8.noarch 21/26 验证 : python3-policycoreutils-2.8-16.1.el8.noarch 22/26 验证 : selinux-policy-3.14.3-98.el8.noarch 23/26 验证 : selinux-policy-3.14.1-61.el8.noarch 24/26 验证 : selinux-policy-targeted-3.14.3-98.el8.noarch 25/26 验证 : selinux-policy-targeted-3.14.1-61.el8.noarch 26/26 已升级: libsemanage-2.9-8.el8.x86_64 policycoreutils-2.9-19.el8.x86_64 policycoreutils-python-utils-2.9-19.el8.noarch python3-libsemanage-2.9-8.el8.x86_64 python3-policycoreutils-2.9-19.el8.noarch selinux-policy-3.14.3-98.el8.noarch selinux-policy-targeted-3.14.3-98.el8.noarch 已安装: container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch containerd.io-1.6.4-3.1.el8.x86_64 docker-ce-3:20.10.16-3.el8.x86_64 docker-ce-cli-1:20.10.16-3.el8.x86_64 docker-ce-rootless-extras-20.10.16-3.el8.x86_64 docker-scan-plugin-0.17.0-3.el8.x86_64 fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86_64 fuse3-3.2.1-12.el8.x86_64 fuse3-libs-3.3.0-15.el8.x86_64 libcgroup-0.41-19.el8.x86_64 libslirp-4.4.0-1.module_el8.6.0+926+8bef8ae7.x86_64 slirp4netns-1.1.8-2.module_el8.7.0+1106+45480ee0.x86_64 完毕!
第五步,启动Docker
1
2systemctl start docker
第六步,验证安装是否成功
1
2docker run hello-world
结果如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18Hello 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/
如果上面的hello实例报如下的错误:
1
2
3
4
5
6
7Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:80f31da1ac7b312ba29d65080fddf797dd76acfb870e677f390d5acba9741b17 Status: Downloaded newer image for hello-world:latest docker: Error response from daemon: failed to create shim task: OCI runtime create failed: unable to retrieve OCI runtime error (open /run/containerd/io.containerd.runtime.v2.task/moby/233c9b6503a6c2f7e6b093011350d5e42c62854dc183b83b3d666a04da27febe/log.json: no such file or directory): runc did not terminate successfully: exit status 127: unknown.
则可以进行如下命令安装
1
2yum install libseccomp-devel
也可以重新配置阿里云镜像,具体就不再此进行说明
最后
以上就是懵懂大船最近收集整理的关于CentOS8下安装Docker的全部内容,更多相关CentOS8下安装Docker内容请搜索靠谱客的其他文章。
发表评论 取消回复