Docker相关

Docker折腾相关

安装(apt)

Debian

卸载旧版本

1
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt remove $pkg; done

使用 apt 软件仓库安装

设置 Docker 的 apt 软件仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
# 添加 Docker 官方的 GPG 密钥:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# 将仓库添加到 Apt 源:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update

安装 Docker 软件包

1
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Ubuntu

卸载旧版本

1
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt remove $pkg; done

使用 apt 软件仓库安装

设置 Docker 的 apt 软件仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
# 添加 Docker 官方的 GPG 密钥:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# 将仓库添加到 Apt 源:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update

如果使用的是 Ubuntu 衍生发行版(例如 Linux Mint),需要使用 UBUNTU_CODENAME 代替 VERSION_CODENAME

安装 Docker 软件包

1
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

卸载(Debian、Ubuntu)

卸载 Docker Engine、CLI、containerd 和 Docker Compose 软件包

1
sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras

主机上的镜像、容器、卷或自定义配置文件不会自动删除。要删除所有镜像、容器和卷,请执行以下命令:

1
2
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

安装(一键安装脚本)

1
2
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh --dry-run

参考

Install Docker Engine on Debian
Install Docker Engine on Ubuntu