卸载旧docker

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

安装依赖,使得apt可以使用https

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

添加docker的GPG key:

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

国内访问download.docker.com不稳定的话可以使用阿里云的

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

设置docker镜像源

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

国内访问download.docker.com不稳定的话可以使用阿里云镜像源

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

安装docker-ce

sudo apt-get install -y docker-ce

启动并设置开机自启动docker

sudo systemctl enable docker && sudo systemctl start docker

将当前登录用户加入docker用户组中

将用户加入该 group 内。然后退出并重新登录就生效啦。

sudo gpasswd -a ${USER} docker