//卸载已安装的旧版本
sudo apt remove docker docker-engine docker.io containerd runc
//配置apt https支持
sudo apt update
sudo apt install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
//添加docker官方的GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
//添加docker官方仓库地址
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 update
sudo apt install docker-ce docker-ce-cli containerd.io
官方文档:Install Docker Engine on Ubuntu | Docker Documentation