1、卸载旧版本
# apt-get remove docker docker-engine docker.io
2、更新apt-get源
# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8
# apt-get update
如果当前源不好用,可以使用中科大的源
cd /etc/apt/
sudo cp sources.list sources.list.bak
sudo vi sources.list
把下面的这些源添加到source.list文件头部:
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
最后更新源和更新已安装的包:
# sudo apt-get update
# sudo apt-get upgrade
2、安装apt的https支持包并添加gpg秘钥
# apt-get install apt-transport-https ca-certificates curl software-properties-common
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
4、安装docker-ce
安装最新的稳定版
# apt-get install -y docker-ce
安装指定版本
获取版本列表
# apt-cache madison docker-ce
指定版本安装(比如版本是17.09.1~ce-0~ubuntu)
# apt-get install -y docker-ce=17.09.1~ce-0~ubuntu
5、接受所有ip的数据包转发
# vi /lib/systemd/system/docker.service
找到ExecStart=xxx,在这行上面加入一行,内容如下:(k8s的网络需要)
ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
6、启动服务
# systemctl daemon-reload
# service docker start
7、添加docker镜像加速源(后续添加私有镜像地址也在这个文件,ubuntu默认没有,需要手动创建)
# vim /etc/docker/daemon.json
{
"registry-mirrors": ["http://f1361db2.m.daocloud.io"]
}
保存退出
8、重启docker以使配置生效
# service docker restart
或
# systemctl restart docker
如果搭建harbor需要安装docker-compose
# apt-get install docker-compose
# docker-compose --version