linux安装docker
- 先更新apt包索引:
sudo apt update
- 添加GPG秘钥
sudo apt-get install apt-transport-https ca-certificates
- 添加软件源
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
- 添加成功后更新软件包缓存
sudo apt-get update
- 安装docker-ce
sudo apt install docker-ce
- 设置开机自启动并启动 Docker-ce(安装成功后默认已设置并启动,可忽略)
sudo systemctl enable docker
sudo systemctl start docker
- 测试运行
sudo docker run hello-world
docker: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/fc/fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e/data?verify=1557478882-B3IuIwGdskoJAgoGLehIsXKMyFA%3D: net/http: TLS handshake timeout.
See 'docker run --help'.
这是因为docker的仓库被墙了,导致连接失败。我们可以更换仓库为国内镜像源:
可以选择阿里云的加速,登录地址:https://cr.console.aliyun.com/cn-shanghai/instances/mirrors
进入打开终端,在/etc/docker文件夹下创建daemon.json文件
cd /etc/docker
sudo vim daemon.json
在打开的文本中输入如下内容:
{
"registry-mirrors": ["https://kklvkq3t.mirror.aliyuncs.com"]
}
保存之后在运行下面两句使修改生效:
systemctl daemon-reload
systemctl restart docker
再次测试:
sudo docker run hello-world
成功!!!
8.这时我们可以输入docker info检验一下镜像仓库是否正确配置
![dockerinfo截图](https://upload-images.jianshu.io/upload_images/5402612-f8606fc86c626c43.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
此时表示安装完成