Ubuntu安装指定版本的docker

Ubuntu安装指定版本的docker

1、删除docker相关组件

#卸载旧版本
apt-get autoremove docker docker-ce docker-engine  docker.io  containerd runc
#清空旧版docker占用的内存 
sudo apt-get remove --auto-remove docker
# 删除无用的相关的配置文件
 dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P 
 #删除相关目录
rm -rf /etc/systemd/system/docker.service.d
rm -rf /var/lib/docker
#更新系统源 
sudo apt-get update


2、安装 apt 依赖包,用于通过HTTPS来获取仓库

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

3、添加阿里云的docker GPG密钥

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

4、添加阿里镜像源 设置稳定版仓库(添加到/etc/apt/sources.list中)

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

#更新 
sudo apt-get update

5、查看有哪些版本

apt-cache madison docker-ce
apt-cache madison docker-ce-cli

6、安装最新/指定版本

#安装最新版 
sudo apt-get install -y docker-ce 

#安装5:20.10.21~3-0~ubuntu-kinetic版 
sudo apt-get install -y docker-ce=5:20.10.21~3-0~ubuntu-kinetic docker-ce-cli=5:20.10.21~3-0~ubuntu-kinetic 

7、验证安装是否成功

docker -version

8、重启Docker

sudo service docker restart 
#或者 
sudo systemctl restart docker

9. 配置阿里容器镜像加速器

vim /etc/docker/daemon.json
#添加registry-mirrors

image

#使配置文件生效
sudo systemctl daemon-reload 
sudo systemctl restart docker
#运行hello-world验证docker-ce是否安装成功

10. 设置docker开机自启

sudo systemctl enable docker

参考文档:
https://blog.csdn.net/s_daqing/article/details/128982516

posted @ 2024-03-19 14:37  michaelchengjl  阅读(183)  评论(0编辑  收藏  举报