检查是否存在安装残留,移除可能会造成冲突的组件。
shell
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
从apt Docker仓库中安装官方GPG key:
shell
sudo apt-get update
sudo apt-get 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
添加源:
shell
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-get update
安装指定版本,列出当前版本操作系统能够使用的版本:
shell
apt-cache madison docker-ce | awk '{ print $3 }'
选择所需要的版本进行安装:
shell
VERSION_STRING=5:27.2.1-1~ubuntu.24.04~noble
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
启动docker服务,查看服务启动情况并配置自动启动:
shell
sudo systemctl start docker
sudo systemctl status docker
docker info
sudo systemctl enable docker
将当前用户添加至docker组内,使当前用户有docker操作权限:
shell
sudo usermod -aG docker $USER