CentOS7安装docker
首选Ubuntu安装,基于Ubuntu发布的
- docker-ce社区免费版
- docker-ee企业收费版
在CentOS 7上安装Docker可以按照以下步骤进行:
1. 更新系统
首先,确保你的系统是最新的,运行以下命令更新系统的所有软件包:
yum update -y
2. 安装必要的依赖包
安装yum-utils包(它提供了yum-config-manager工具),以及一些用于允许yum使用HTTPS源的依赖包:
yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
[root@192 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本
软件包 device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 已安装并且是最新版本
软件包 7:lvm2-2.02.187-6.el7_9.5.x86_64 已安装并且是最新版本
无须任何处理
[root@192 ~]#
3. 为yum添加可以下载Docker的镜像源
为了加快下载速度,你可以使用国内的镜像源,这里以阿里云镜像源为例:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@192 ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@192 ~]# cd /etc/yum.repos.d/
[root@192 yum.repos.d]# ll
总用量 44
-rw-r--r--. 1 root root 2523 8月 4 2022 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 5月 21 2024 CentOS-CR.repo
-rw-r--r--. 1 root root 649 5月 21 2024 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 5月 21 2024 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 5月 21 2024 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 5月 21 2024 CentOS-Sources.repo
-rw-r--r--. 1 root root 9454 5月 21 2024 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 5月 21 2024 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 2081 2月 15 20:26 docker-ce.repo
[root@192 yum.repos.d]#
4. 安装docker-ce
安装最新版本的Docker Engine和容器化运行时:
[root@192 ~]# yum install docker-ce.x86_64 docker-ce-cli
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
docker-ce-stable | 3.5 kB 00:00:00
(1/2): docker-ce-stable/7/x86_64/primary_db | 152 kB 00:00:00
(2/2): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.3.26.1.4-1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 3:docker-ce-26.1.4-1.el7.x86_64 需要
--> 正在处理依赖关系 containerd.io >= 1.6.24,它被软件包 3:docker-ce-26.1.4-1.el7.x86_64 需要
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-26.1.4-1.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.26.1.4-1.el7 将被 安装
--> 正在处理依赖关系 docker-buildx-plugin,它被软件包 1:docker-ce-cli-26.1.4-1.el7.x86_64 需要
--> 正在处理依赖关系 docker-compose-plugin,它被软件包 1:docker-ce-cli-26.1.4-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.119.2-1.911c772.el7_8 将被 安装
---> 软件包 containerd.io.x86_64.0.1.6.33-3.1.el7 将被 安装
---> 软件包 docker-buildx-plugin.x86_64.0.0.14.1-1.el7 将被 安装
---> 软件包 docker-ce-rootless-extras.x86_64.0.26.1.4-1.el7 将被 安装
--> 正在处理依赖关系 fuse-overlayfs >= 0.7,它被软件包 docker-ce-rootless-extras-26.1.4-1.el7.x86_64 需要
--> 正在处理依赖关系 slirp4netns >= 0.4,它被软件包 docker-ce-rootless-extras-26.1.4-1.el7.x86_64 需要
---> 软件包 docker-compose-plugin.x86_64.0.2.27.1-1.el7 将被 安装
--> 正在检查事务
---> 软件包 fuse-overlayfs.x86_64.0.0.7.2-6.el7_8 将被 安装
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.2)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.0)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3()(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
---> 软件包 slirp4netns.x86_64.0.0.4.3-4.el7_8 将被 安装
--> 正在检查事务
---> 软件包 fuse3-libs.x86_64.0.3.6.1-4.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==========================================================================================================================
Package 架构 版本 源 大小
==========================================================================================================================
正在安装:
docker-ce x86_64 3:26.1.4-1.el7 docker-ce-stable 27 M
docker-ce-cli x86_64 1:26.1.4-1.el7 docker-ce-stable 15 M
为依赖而安装:
container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k
containerd.io x86_64 1.6.33-3.1.el7 docker-ce-stable 35 M
docker-buildx-plugin x86_64 0.14.1-1.el7 docker-ce-stable 14 M
docker-ce-rootless-extras x86_64 26.1.4-1.el7 docker-ce-stable 9.4 M
docker-compose-plugin x86_64 2.27.1-1.el7 docker-ce-stable 13 M
fuse-overlayfs x86_64 0.7.2-6.el7_8 extras 54 k
fuse3-libs x86_64 3.6.1-4.el7 extras 82 k
slirp4netns x86_64 0.4.3-4.el7_8 extras 81 k
事务概要
==========================================================================================================================
安装 2 软件包 (+8 依赖软件包)
总下载量:114 M
安装大小:401 M
Is this ok [y/d/N]: y
Downloading packages:
(1/10): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.14.1-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
docker-buildx-plugin-0.14.1-1.el7.x86_64.rpm 的公钥尚未安装
(2/10): docker-buildx-plugin-0.14.1-1.el7.x86_64.rpm | 14 MB 00:00:04
(3/10): containerd.io-1.6.33-3.1.el7.x86_64.rpm | 35 MB 00:00:05
(4/10): docker-ce-cli-26.1.4-1.el7.x86_64.rpm | 15 MB 00:00:02
(5/10): docker-ce-rootless-extras-26.1.4-1.el7.x86_64.rpm | 9.4 MB 00:00:02
(6/10): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:00
(7/10): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:00
(8/10): docker-ce-26.1.4-1.el7.x86_64.rpm | 27 MB 00:00:04
(9/10): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:00
(10/10): docker-compose-plugin-2.27.1-1.el7.x86_64.rpm | 13 MB 00:00:01
--------------------------------------------------------------------------------------------------------------------------
总计 10 MB/s | 114 MB 00:00:11
从 https://mirrors.aliyun.com/docker-ce/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
用户ID : "Docker Release (CE rpm) <docker@docker.com>"
指纹 : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
来自 : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 1/10
正在安装 : containerd.io-1.6.33-3.1.el7.x86_64 2/10
正在安装 : docker-buildx-plugin-0.14.1-1.el7.x86_64 3/10
正在安装 : slirp4netns-0.4.3-4.el7_8.x86_64 4/10
正在安装 : fuse3-libs-3.6.1-4.el7.x86_64 5/10
正在安装 : fuse-overlayfs-0.7.2-6.el7_8.x86_64 6/10
正在安装 : docker-compose-plugin-2.27.1-1.el7.x86_64 7/10
正在安装 : 1:docker-ce-cli-26.1.4-1.el7.x86_64 8/10
正在安装 : docker-ce-rootless-extras-26.1.4-1.el7.x86_64 9/10
正在安装 : 3:docker-ce-26.1.4-1.el7.x86_64 10/10
验证中 : docker-compose-plugin-2.27.1-1.el7.x86_64 1/10
验证中 : fuse3-libs-3.6.1-4.el7.x86_64 2/10
验证中 : fuse-overlayfs-0.7.2-6.el7_8.x86_64 3/10
验证中 : slirp4netns-0.4.3-4.el7_8.x86_64 4/10
验证中 : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 5/10
验证中 : containerd.io-1.6.33-3.1.el7.x86_64 6/10
验证中 : 3:docker-ce-26.1.4-1.el7.x86_64 7/10
验证中 : 1:docker-ce-cli-26.1.4-1.el7.x86_64 8/10
验证中 : docker-ce-rootless-extras-26.1.4-1.el7.x86_64 9/10
验证中 : docker-buildx-plugin-0.14.1-1.el7.x86_64 10/10
已安装:
docker-ce.x86_64 3:26.1.4-1.el7 docker-ce-cli.x86_64 1:26.1.4-1.el7
作为依赖被安装:
container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.6.33-3.1.el7
docker-buildx-plugin.x86_64 0:0.14.1-1.el7 docker-ce-rootless-extras.x86_64 0:26.1.4-1.el7
docker-compose-plugin.x86_64 0:2.27.1-1.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8
fuse3-libs.x86_64 0:3.6.1-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8
完毕!
[root@192 ~]#
在安装过程中,当提示是否安装和是否接受GPG key时,输入y并回车确认。
5. 启动并设置Docker开机自启
安装完成后,启动Docker服务:
[root@192 桌面]# systemctl start docker
设置Docker服务在系统启动时自动启动:
[root@192 桌面]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@192 桌面]#
查看docker信息
docker -v
[root@192 桌面]# docker -v #查看版本
Docker version 26.1.4, build 5650f9b
[root@192 ~]# docker info #查看docker配置信息
# 客户端环境配置
Client: Docker Engine - Community # docker引擎-社区版
Version: 26.1.4
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.) # buildx 构建工具(v0.14.1)
Version: v0.14.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.) # compose 编排工具(v2.27.1)
Version: v2.27.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
# 服务端运行时状态
Server:
Containers: 1 # 容器数量 1个
Running: 1 # 运行中 1个
Paused: 0 # 暂停 1个
Stopped: 0 # 停止 1个
Images: 1 # 镜像数量 1个
Server Version: 26.1.4
Storage Driver: overlay2 # 存储驱动 overlay2
Backing Filesystem: xfs # 备份文件系统 xfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file # 日志驱动
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay # 支持的网络模式: 桥接/主机/IPVLAN等
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: d2d58213f83a351ca8f528a95fbd145f5654e957
runc version: v1.1.12-0-g51d5e94
init version: de40ad0
Security Options:
seccomp
Profile: builtin
# 宿主机系统信息
Kernel Version: 3.10.0-693.el7.x86_64 # 内核版本: 3.10
Operating System: CentOS Linux 7 (Core) # 操作系统 centos7
OSType: linux # 系统类型
Architecture: x86_64 # CPU架构: x86_64
CPUs: 3 # 3核
Total Memory: 3.843GiB # 内存总量: 3.84GB
Name: 192.168.27.140
ID: d08e2f22-3087-49c7-bc79-fe8619a63c5d
Docker Root Dir: /var/lib/docker # 数据存储目录: /var/lib/docker
# 镜像仓库配置
Debug Mode: false
Experimental: false
Insecure Registries: # 非安全仓库: 本地回环地址段
127.0.0.0/8
Registry Mirrors: # 镜像加速器
https://hub.rat.dev/
https://docker.1panelproxy.com/
https://docker.1ms.run/
https://docker.aityp.com/
https://docker.anye.in/
Live Restore Enabled: false
docker --help

浙公网安备 33010602011771号