安装docker遇到的坑

1.docker只支持centos7以上的系统,所以刚开始用了一台centos6.8的服务器失败了

2.如果有的话,删除旧的版本

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

3.安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。

yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

4.设置稳定的源

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

上面这步网络不稳定会设置失败,需要多试几次

5.安装最新版本的 Docker Engine-Community 和 containerd

yum install docker-ce docker-ce-cli containerd.io

同样因为网络原因,会失败,我这里失败的原因是:
docker-ce-stable/x86_64/update FAILED
https://download.docker.com/linux/centos/7/x86_64/stable/repodata/65c4f66e2808d328890505c3c2f13bb35a96f457d1c21a6346191c4dc07e6080-updateinfo.xml.gz: [Errno 14] curl#6 - "Could not resolve host: download.docker.com; Name or service not known"
解决办法:单独下载N次直到成功

wget https://download.docker.com/linux/centos/7/x86_64/stable/repodata/65c4f66e2808d328890505c3c2f13bb35a96f457d1c21a6346191c4dc07e6080-updateinfo.xml.gz

成功后再试上面的命令就可以安装了

6.启动docker

systemctl start docker

7.测试一下

docker run hello-world

结果:

[root@iZuf6bzvz55uz2qm19or1yZ tools]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete


docker: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/fc/fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e/data?verify=1585323786-ZG%2BMZ%2FW5B%2B3su95dTQyGPFfb0vY%3D: read tcp 172.19.65.217:43764->104.18.122.25:443: read: connection reset by peer.
See 'docker run --help'.

同样因为网络问题,失败了

解决办法:

配置镜像加速器

在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)

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

之后重新启动服务:

systemctl daemon-reload
systemctl restart docker

结果:

[root@iZuf6bzvz55uz2qm19or1yZ tools]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Already exists
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

就成功了!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值