一、安装Docker Engine

(一) 手动安装: 

1. 配置Docker的GPG key和apt源

# Add Docker's official GPG key:
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

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

2. 安装Docker

(1) 安装当前最新版本的Docker
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
(2) 安装指定版本的Docker
VERSION_STRING=5:29.4.3-1~ubuntu.24.04~noble
sudo apt install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin

(二) 通过脚本自动化安装:(默认安装当前最新版本)

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh

(三) 安装完成

 1. 配置Docker用户组

成功配置docker用户组后,docker用户组内的用户不需要sudo权限即可执行docker相关命令

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

2. 验证Docker是否启动

(1) 查询当前docker服务的状态
sudo systemctl status docker
(2) 如果docker未运行,启动docker服务
sudo systemctl start docker

3. 运行示例Docker image

docker run hello-world

二、卸载Docker:

1. 卸载packages

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

2. 删除Images Containers和Volumes

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

3. 删除apt源和密钥环

sudo rm /etc/apt/sources.list.d/docker.sources
sudo rm /etc/apt/keyrings/docker.asc

参考文献:

Install Docker Engine on Ubuntu | Docker Docs

更多推荐