(CentOS 7 | Rocky 9) 安装 Docker

其实网上相关的文章已经非常多了,所以这篇文章的作用只是记录和明确一条确定可行的操作路径,为以后的操作节省时间,毕竟像我一样大部分人都不是专业的系统管理员,能够快速解决问题就可以了,并不想做过多的专业研究与探索。

本操作手册是官方手册与网上手册的结合版本,集两家之所长,亲自操作可用。

 1# 查看系统版本
 2$ cat /etc/redhat-release
 3> CentOS Linux release 7.6.1810 (Core) // CentOs 7 以上版本
 4
 5# 查看系统内核版本
 6$ uname -r
 7> 4.10.4-1.el7.elrepo.x86_64 // 内核版本要>3.10
 8
 9# 卸载旧版本
10$ yum remove docker \
11            docker-client \
12            docker-client-latest \
13            docker-common \
14            docker-latest \
15            docker-latest-logrotate \
16            docker-logrotate \
17            docker-selinux \
18            docker-engine-selinux \
19            docker-engine
20
21# 安装依赖包
22$ yum install -y yum-utils lvm2 \
23                device-mapper-persistent-data \
bash
 1# 如果系统已切换到阿里云镜像源地址,可跳过此步。
 2# 阿里云镜像自带docker源
 3$ yum-config-manager \
 4    --add-repo \
 5    https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
 6
 7# 使用官方源
 8$ yum-config-manager \
 9    --add-repo \
10    https://download.docker.com/linux/centos/docker-ce.repo
11
12$ yum makecache fast
13# CentOS 8 or Rocky 9 使用timer替换fast
14$ yum makecache timer
bash
1# 如果在 Rocky 9 系统上,会提示containerd.io版本过低,或下载失败,需要独立安装containerd.io
2# 可以重试几次
3$ yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
bash
1// /etc/docker/daemon.json
2{
3  // 添加官方仓库镜像地址,其实也没什么用很慢
4  "registry-mirrors": ["https://registry.docker-cn.com"]
5}
json
1# 设为开机启动
2$ systemctl enable docker.service
3# 启动服务
4$ systemctl start docker.service
bash
 1$ docker run hello-world
 2
 3Unable to find image 'hello-world:latest' locally
 4latest: Pulling from library/hello-world
 51b930d010525: Pull complete
 6Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
 7Status: Downloaded newer image for hello-world:latest
 8
 9Hello from Docker!
10This message shows that your installation appears to be working correctly.
11
12To generate this message, Docker took the following steps:
13 1. The Docker client contacted the Docker daemon.
14 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
15    (amd64)
16 3. The Docker daemon created a new container from that image which runs the
17    executable that produces the output you are currently reading.
18 4. The Docker daemon streamed that output to the Docker client, which sent it
19    to your terminal.
20
21To try something more ambitious, you can run an Ubuntu container with:
22 $ docker run -it ubuntu bash
23
24Share images, automate workflows, and more with a free Docker ID:
25 https://hub.docker.com/
26
27For more examples and ideas, visit:
28 https://docs.docker.com/get-started/
29
30$ docker compose version
31Docker Compose version vX.X.0
bash

若能正常输出以上信息,则说明安装成功。

相关专栏文章