Ubuntu 16.04使用国内源安装docker指定版本教程
1. 若安装过旧版本,需要卸载。执行
sudo apt-get remove docker docker-engine docker.io
2. 安装指定版本的 docker
a. 更新一下软件源库信息,执行
apt-get
update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
b. 添加 阿里云 GPG **
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
c. 设置apt仓库地址(阿里云的apt仓库),执行
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
(lsb_release -cs) \
stable"
d.再次执行
sudo apt-get
update
e. 执行apt-cache madison docker-ce查看可安装的版本.不指定版本则默认安装最新版本,在这里是docker18.09.8, 这里以安装指定版本docker18.09.7为例,执行安装命令
sudo apt-get install docker-ce=5:18.09.7~3-0~ubuntu.xenial
注意,安装指定版本时,图中红色方框圈起来的那一列版本名称是啥就应该替换成啥
f. 安装完毕后,系统默认开启,可以执行
systemctl status docker
查看是否安装成功
2. 为docker配置代理,以便测试运行
a.创建文件夹docker.service.d,在此目录下新建文件http-proxy.conf;
vi /etc/systemd/system/docker.service.d/http-proxy.conf
b.在http-proxy.conf中添加
[Service]
Environment="HTTP_PROXY=http://username:[email protected]:8080/"
c. 重新运行docker守护进程
systemctl daemon-reload
d. 检查环境变量是否写入
systemctl show --property Environment docker.
e. 重启docker服务
service docker restart
f.对docker进行测试,运行
sudo docker run hello-world
出现如下界面则表示测试成功