Docker
安装
docker
自动安装
使用官方安装脚本自动安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
docker
手动安装
环境准备
- 需要会一点
Linux
基础 Ubuntu
(有一台Linux
服务器,虽然docker
可以在Windows
/Mac OS
上安装,但是还是希望使用Linux
系统)xShell
远程连接服务器操作
环境查看
# 系统内核
$ uname -r
5.11.0-25-generic
# 系统版本
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
安装
帮助文档:docs.docker.com/engine/inst…
1.卸载旧版本
$ sudo apt-get remove docker docker-engine docker.io containerd runc
2.需要的安装包
- 更新 apt 包索引。
$ sudo apt-get update
- 安装
apt
依赖包,用于通过HTTPS
来获取仓库:
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
3.添加Docker
的GPG
密钥
- 官方,不推荐
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- 阿里云,推荐
$ curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
4.验证您现在是否拥有带有指纹的密钥。
$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
5.设置稳定仓库
- 官方 不推荐
$ echo \
"deb [arch=amd64 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
- 阿里云 推荐
$ sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
6.安装Docker
引擎
-
安装最新版本
- 更新
apt
包索引
$ sudo apt-get update
- 安装最新版本的
Docker Engine
和containerd
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
- 更新
-
安装指定版本
- 先列出存储库中可用的版本:
$ apt-cache madison docker-ce #以下为docker版本 docker-ce | 5:20.10.8~3-0~ubuntu-focal | https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.8~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.7~3-0~ubuntu-focal | https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.7~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.6~3-0~ubuntu-focal | https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
- 选择指定版本安装
$ sudo apt-get install docker-ce=5:20.10.8~3-0~ubuntu-focal docker-ce-cli=5:20.10.8~3-0~ubuntu-focal containerd.io
docker-ce: 社区版,官方推荐
docker-ee:企业版