Ubuntu 下安装 Docker
先卸载旧版本:
$ sudo apt-get remove docker docker-engine docker.io containerd runc
Allow apt
to use a repository over HTTPS:
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
添加 Docker 的官方 GPG 密钥:
$ curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
添加 Docker 的远程库,使用阿里云的镜像:
$ sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
# sudo add-apt-repository \
# "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
# $(lsb_release -cs) \
# stable"
安装:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
修改为国内源:
$ sudo vim /etc/docker/daemon.json
# 添加以下内容
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
重启 Docker
$ sudo systemctl restart docker.service
验证是否安装成功:
$ sudo docker run hello-world
参见 Ubuntu 上安装 Docker 的官方文档
将当前用户添加到 docker 用户组,避免每次都要输入 sudo:
$ sudo gpasswd -a <用户名> docker
# 然后重启 docker 服务
$ sudo service docker restart
# 还需要重新登录
$ exit