Ubuntu安装docker

1.安装docker

1.1.卸载旧版本

ubuntu下自带了docker的库,不需要添加新的源。但是版本过低,卸载重装

sudo apt-get remove docker docker-engine docker.io containerd runc

1.2.获取软件最新源

sudo apt-get update

1.3.安装 apt 依赖包

用于通过HTTPS来获取仓库

sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

1.4.安装GPG证书

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

1.5.验证

sudo apt-key fingerprint 0EBFCD88

image-20230810235330758

1.6.设置稳定版仓库

sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

2.安装 Docker Engine-Community

2.1.更新 apt 包索引

sudo apt-get update

提示:以下两种安装方式,选择一种即可

2.2.安装最新版本

sudo apt-get install docker-ce docker-ce-cli containerd.io

2.3.安装特定版本

apt-cache madison docker-ce

sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

VERSION_STRING版本字符串表示安装特定版本,例如5:20.10.17~3-0~ubuntu-focal

2.4.测试

sudo docker run hello-world

提示:显示以下结果,表示安装成功

image-20230810235858467

2.5.启动

systemctl start docker

2.6.停止

 systemctl stop docker

2.7.重启

systemctl restart docker

2.8.设置开机启动

sudo systemctl enable docker

3.卸载

3.1.删除安装包

sudo apt-get autoremove docker docker-ce docker-engine docker.io containerd runc

3.2.删除相关配置文件

dpkg -l | grep docker

dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P 

3.3.卸载相关插件

sudo apt-get autoremove docker-ce-*

3.4.删除docker的相关配置

sudo rm -rf /etc/systemd/system/docker.service.d

sudo rm -rf /var/lib/docker

3.5.查询下docker相关软件包

dpkg -l | grep docker
提示 如果还有包存在,则删除,可能会有多个
sudo apt remove --purge xxx

3.6.验证

docker -v