Docker在CentOS/Rocky/Ubuntu上安装和镜像加速驱动修改
简介
如何在 Linux 上安装 Docker 容器。Docker CE 镜像下载
配置方法
使用官方安装脚本自动安装
# Docker官方安装脚本
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# 启动Docker服务
sudo systemctl start docker
sudo systemctl enable docker
CentOS/Rocky (使用 yum 进行安装)
# step 1: 安装必要的一些系统工具
yum install -y yum-utils
# Step 2: 添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 安装Docker
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Step 4: 开启Docker服务
systemctl enable docker --now
# 注意:
# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
# vim /etc/yum.repos.d/docker-ce.repo
# 将[docker-ce-test]下方的enabled=0修改为enabled=1
#
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# [root@localhost ~]# yum list docker-ce --showduplicates | sort -r
# docker-ce.x86_64 3:29.9.2-1.el10 docker-ce-stable
# docker-ce.x86_64 3:29.9.1-1.el10 docker-ce-stable
# docker-ce.x86_64 3:29.9.0-1.el10 docker-ce-stable
# docker-ce.x86_64 3:29.8.2-1.el10 docker-ce-stable
# docker-ce.x86_64 3:29.8.1-1.el10 docker-ce-stable
# docker-ce.x86_64 3:29.8.0-1.el10 docker-ce-stable
# Step2: 安装指定版本的Docker-CE: (VERSION=29.9.2-1.el10)
# sudo yum -y install docker-ce-[VERSION]
# [root@localhost ~]# yum -y install docker-ce-29.9.2-1.el10
Ubuntu(使用 apt-get 进行安装)
# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
# step 2: 信任 Docker 的 GPG 公钥
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Step 3: 写入软件源信息
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Step 4: 安装Docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# apt-cache madison docker-ce
# docker-ce | 29.9.2-1~ce-0~ubuntu-xenial | https://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
# docker-ce | 29.9.2-1~ce-0~ubuntu-xenial | https://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
# Step 2: 安装指定版本的Docker-CE: (VERSION例如上面的29.9.2-1~ce-0~ubuntu-xenial)
# sudo apt-get -y install docker-ce=[VERSION]
安装校验
# 查看版本
[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 29.9.2
API version: 1.56
Go version: go1.26.10
Git commit: a82e528
Built: Tue Oct 20 18:47:45 2026
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 29.9.2
API version: 1.56 (minimum version 1.40)
Go version: go1.26.10
Git commit: 0367cbe
Built: Tue Oct 20 18:44:34 2026
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v2.4.2
GitCommit: b7a25261e029d68978bbf290df0a62fc819b3c51
runc:
Version: 1.5.2
GitCommit: v1.5.2-0-g29dd3dc2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
# 通过运行 hello-world 映像验证是否正确安装了 docker-ce
[root@localhost ~]# docker run hello-world
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/
镜像加速
# 镜像加速
sudo tee /etc/docker/daemon.json > /dev/null <<'EOF'
{
"registry-mirrors": [
"https://docker.xuanyuan.me",
"https://docker.1ms.run",
"https://docker-0.unsee.tech",
"https://docker.1panel.live",
"https://hub.rat.dev",
"https://docker.fxxk.dedyn.io",
"https://k8s.m.daocloud.io"
]
}
EOF
systemctl daemon-reload && systemctl restart docker
# 镜像加速和驱动修改
sudo tee /etc/docker/daemon.json > /dev/null <<'EOF'
{
"registry-mirrors": ["https://docker.1ms.run"],
"insecure-registries": ["10.10.10.10", "harbor.local"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
相关链接
- 官方网址:https://www.docker.com
- 安装资料:https://docs.docker.com/desktop/setup/install/linux/
- 项目地址:https://github.com/moby/moby
- 安装资料:https://docs.docker.com/engine/install/
- 产品介绍:https://docs.docker.com/retired/ https://www.mirantis.com/
- 阿里仓库:https://developer.aliyun.com/mirror/docker-ce
- 清华仓库:https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/

浙公网安备 33010602011771号