参考资料:Install Docker Engine | Docker Docs
版本支持
centos:
- CentOS 7
- CentOS 8 (stream)
- CentOS 9 (stream)
ubuntu:
- Ubuntu Lunar 23.04
- Ubuntu Kinetic 22.10
- Ubuntu Jammy 22.04 (LTS)
- Ubuntu Focal 20.04 (LTS)
使用脚本安装
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
启动docker
sudo systemctl start docker
演示
centos7:
# 卸载旧版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 安装命令
[root@192 ~]# curl -fsSL https://get.docker.com -o get-docker.sh
[root@192 ~]# sudo sh ./get-docker.sh
# 安装过程
# Executing docker install script, commit: e5543d473431b782227f8908005543bb4389b8de
+ sh -c 'yum install -y -q yum-utils'
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
警告:/var/cache/yum/x86_64/7/base/packages/python-kitchen-1.1.1-5.el7.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
python-kitchen-1.1.1-5.el7.noarch.rpm 的公钥尚未安装
libxml2-python-2.9.1-6.el7_9.6.x86_64.rpm 的公钥尚未安装
导入 GPG key 0xF4A80EB5:
用户ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
软件包 : centos-release-7-6.1810.2.el7.centos.x86_64 (@anaconda)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
+ sh -c 'yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo'
已加载插件:fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/other_db | 2.6 MB 00:00:00
(2/10): base/7/x86_64/filelists_db | 7.2 MB 00:00:01
(3/10): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:01
(4/10): docker-ce-stable/7/x86_64/primary_db | 117 kB 00:00:00
(5/10): extras/7/x86_64/filelists_db | 303 kB 00:00:00
(6/10): extras/7/x86_64/other_db | 150 kB 00:00:00
(7/10): docker-ce-stable/7/x86_64/other_db | 135 kB 00:00:00
(8/10): docker-ce-stable/7/x86_64/filelists_db | 47 kB 00:00:02
(9/10): updates/7/x86_64/other_db | 1.4 MB 00:00:00
(10/10): updates/7/x86_64/filelists_db | 13 MB 00:00:01
元数据缓存已建立
+ sh -c 'yum install -y -q docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin'
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.11.2-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
docker-buildx-plugin-0.11.2-1.el7.x86_64.rpm 的公钥尚未安装
导入 GPG key 0x621E9F35:
用户ID : "Docker Release (CE rpm) <docker@docker.com>"
指纹 : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
来自 : https://download.docker.com/linux/centos/gpg
================================================================================
To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:
dockerd-rootless-setuptool.sh install
Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.
To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/
WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the 'Docker daemon attack surface'
documentation for details: https://docs.docker.com/go/attack-surface/
================================================================================
[root@192 ~]#
# 启动服务
[root@192 ~]# systemctl start docker
# 查看docker版本号
[root@192 ~]# docker --version
Docker version 24.0.6, build ed223bc
ubuntu20.04
# 卸载旧版本
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
# 安装命令
root@ubuntu:~# curl -fsSL https://get.docker.com -o get-docker.sh
root@ubuntu:~# sudo sh ./get-docker.sh
# 注意:如果安装失败,请更新ubuntu的安装源,本文演示使用的阿里云源,配置方式参考:https://www.cnblogs.com/zqifa/p/12910989.html
# 安装过程
# Executing docker install script, commit: e5543d473431b782227f8908005543bb4389b8de
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c install -m 0755 -d /etc/apt/keyrings
+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
+ sh -c chmod a+r /etc/apt/keyrings/docker.gpg
+ sh -c echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu focal stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin >/dev/null
+ sh -c docker version
Client: Docker Engine - Community
Version: 24.0.6
API version: 1.43
Go version: go1.20.7
Git commit: ed223bc
Built: Mon Sep 4 12:32:12 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.6
API version: 1.43 (minimum version 1.12)
Go version: go1.20.7
Git commit: 1a79695
Built: Mon Sep 4 12:32:12 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.24
GitCommit: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
runc:
Version: 1.1.9
GitCommit: v1.1.9-0-gccaecfc
docker-init:
Version: 0.19.0
GitCommit: de40ad0
================================================================================
To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:
dockerd-rootless-setuptool.sh install
Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.
To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/
WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the 'Docker daemon attack surface'
documentation for details: https://docs.docker.com/go/attack-surface/
================================================================================
root@ubuntu:~#
# 启动docker
root@ubuntu:~# systemctl start docker
# 查看docker版本号
root@ubuntu:~# docker --version
Docker version 24.0.6, build ed223bc
配置docker镜像加速
镜像加速地址和配置方法可以在阿里云控制台的“容器镜像服务”--“镜像工具”--“镜像加速器”页面查看
命令参考(加速地址需要修改为自己的有效地址,每个用户的id不同):
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://jxxxxxx3.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
centos7系统演示:
[root@192 ~]# sudo mkdir -p /etc/docker
[root@192 ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://jxxxxxx3.mirror.aliyuncs.com"]
> }
> EOF
{
"registry-mirrors": ["https://jxxxxxx3.mirror.aliyuncs.com"]
}
[root@192 ~]# sudo systemctl daemon-reload
[root@192 ~]# sudo systemctl restart docker
[root@192 ~]#