国内源安装docker

考虑到版本的更新变化,安装还是建议参考官网文档:

https://docs.docker.com/install/linux/docker-ce/ubuntu/

https://docs.docker.com/install/linux/linux-postinstall/

因为网络原因,在官网文档的基础上,修改为使用国内源安装

1.卸载原有版本

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

/var/lib/docker/ 中的内容会被保留,包括镜像、容器、卷和网络。如果需要删除所有镜像,容器和卷(第一次安装请忽略):

sudo rm -rf /var/lib/docker

如果使用 apt-get remove 配置文件会保留,彻底删除请用purge命令

dpkg -l | grep docker
sudo apt-get purge docker-ce(有些旧版名字是docker)

2.更新索引包

sudo apt-get update

3.安装HTTPS支持包

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

4.添加软件源的GPG密钥

中科大:

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

中科大镜像文档:http://mirrors.ustc.edu.cn/help/docker-ce.html

阿里云:

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

阿里云镜像站文档:https://yq.aliyun.com/articles/110806/

清华:

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

 (你没看错,清华源用的官方公钥),清华镜像文档:https://mirror.tuna.tsinghua.edu.cn/help/docker-ce/

官方源:

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

注意,官网上有要求通过搜索指纹的最后8个字符,验证您现在拥有指纹9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88的密钥

sudo apt-key fingerprint 0EBFCD88
    
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

5.向 source.list 中添加Docker软件源

中科大源:

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

阿里源:

sudo add-apt-repository \
    "deb [arch=amd64] http://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 add-apt-repository \
   "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

6.更新索引包

sudo apt-get update

7.安装

该命令直接安装最新版本

sudo apt-get install docker-ce docker-ce-cli containerd.io

如果想要指定安装版本,运行命令查看源内各版本:

apt-cache madison docker-ce

在显示的版本里选择一个安装即可:

sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

【可选】测试是否安装成功,此命令会下载一个镜像来运行

sudo docker run hello-world

8.启动后台服务

sudo service docker start

9.查看版本

docker version

10.镜像加速

新版的 Docker 使用 /etc/docker/daemon.json 来配置 Daemon。

请在该配置文件中加入(没有就先建一个)Docker中国官方加速:

{
    "registry-mirrors": ["https://registry.docker-cn.com"]
}

重启生效:

sudo service docker restart

11.添加当前用户到docker组(可选)

为了不用一直使用sudo权限,可以把自己的账户加入到docker里,首先是创建docker组:

sudo groupadd docker

当前用户加入docker组:

sudo usermod -aG docker $USER

检查创建是否有效:

cat /etc/group

重新注销并登录,激活group的修改,或者用以下命令:

newgrp docker

重启:

sudo systemctl restart docker

12.设置docker自启动选项

开启自启动

sudo systemctl enable docker

关闭自启动

sudo systemctl disable docker

 ubuntu14.10一下使用upstart

13.Docker daemon的使用请参照官方文档

https://docs.docker.com/config/daemon/systemd/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值