可以参考以下官方安装地址:Install Docker Engine on Ubuntu | Docker Documentation
要安装 Docker Engine,需要以下 Ubuntu 版本之一的 64 位版本:
- Ubuntu 小鬼 21.10
- Ubuntu 多毛 21.04
- Ubuntu 焦点 20.04 (LTS)
- Ubuntu 仿生 18.04 (LTS)
卸载老版本
$ sudo apt-get remove docker docker-engine docker.io containerd runc
设置新的储存器
更新apt包索引并安装包以允许apt通过 HTTPS 使用存储库
$ sudo apt-get update
$ sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
添加官方的GPG密钥
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
使用以下命令设置稳定存储库
$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
安装 Docker 引擎
$ sudo apt-get update
问题: E: The repository 'Index of linux/ubuntu/ \ Release' does not have a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details
忽略即可
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
报错: Reading package lists... Done Building dependency tree Reading state information... Done Package docker-ce is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source
E: Package 'docker-ce' has no installation candidate E: Unable to locate package docker-ce-cli E: Unable to locate package containerd.io E: Couldn't find any package by glob 'containerd.io' E: Couldn't find any package by regex 'containerd.io'
两种方法:
1、编辑ubuntu源 /etc/apt/sources.list
$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.back
$ sudo vi /etc/apt/sources.list
最后增加
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
2、还是sources.list,替换为
清华镜像https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
$ sudo apt-get update
Hit:1 Index of /ubuntu focal InRelease Hit:2 Index of /ubuntu focal-security InRelease Get:3 Index of linux/ubuntu/ bionic InRelease [64.4 kB] Err:3 Index of linux/ubuntu/ bionic InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8 Hit:4 Index of /ubuntu focal-updates InRelease Get:5 Index of linux/ubuntu/ focal InRelease [57.7 kB] Err:5 Index of linux/ubuntu/ focal InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8 Hit:6 Index of /ubuntu focal-backports InRelease Reading package lists... Done W: GPG error: Index of linux/ubuntu/ bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8 E: The repository 'Index of linux/ubuntu/ bionic InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. W: GPG error: Index of linux/ubuntu/ focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8 E: The repository 'Index of linux/ubuntu/ focal InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details.
将公钥添加至服务器,即终端中输入
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys '7EA0A9C3F273FCD8'
Executing: /tmp/apt-key-gpghome.VIv8eLEwb3/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8
gpg: key 8D81803C0EBFCD88: 9 signatures not checked due to missing keys
gpg: key 8D81803C0EBFCD88: public key "Docker Release (CE deb) <docker@docker.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
添加镜像加速(阿里云的,可以自行去官网注册,是免费的呦)
$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://mirror.aliyuncs.com"]
}
EOF
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
这里的registry-mirrors
可以替换成任意源