CentOS7安装Docker遇到的问题笔记

笔记/朱季谦

以下是笔者本人学习搭建docker过程当中记录的一些实践笔记,过程当中也遇到了一些坑,但都解决了,就此记录,留作以后再次搭建时可以直接参考。

一、首先,先检查CentOS版本,保证在CentOS7版本以上,系统内核在3.10以上——

[root@192 opt]# uname -r
3.10.0-693.el7.x86_64

二、卸载旧的docker版本

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

三、安装需要的依赖包

sudo yum install -y yum-utils

四、设置国内镜像的仓库

sudo yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

五、更新yum软件包索引

yum makecache fast 

六、安装docker相关 docker-ce 社区 docker ee企业版

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

七、启动docker

systemctl start docker

这时,出现了一个很奇怪的异常:

Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

不慌,我们先检查一下daemon.json文件格式:

vim /etc/docker/daemon.json

发现这个daemon.json文件里是这样的,也不知道为啥直接更新下载后,它会缺少了部分字符......

image

需要修改成这样,就可以了

{"registry-mirrors": ["http://9600955f.m.daocloud.io"],"insecure-registries": []
}

接下来,可以正常启动docker了——

[root@192 opt]# systemctl daemon-reload
[root@192 opt]# systemctl start docker

如果不报错,输入systemctl status docker.service,若显示以下信息则证明启动安装并启动成功:

image

安装成功后,使用docker version,一般会出现以下信息:

[root@192 opt]# docker version
Client: Docker Engine - Community
 Version:           20.10.8
 API version:       1.41
 Go version:        go1.16.6
 Git commit:        3967b7d
 Built:             Fri Jul 30 19:55:49 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.8
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.6
  Git commit:       75249d8
  Built:            Fri Jul 30 19:54:13 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

尝试下拉取hello-world时,发现出现一个超时问题:

[root@192 opt]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/library/hello-world/manifests/sha256:393b81f0ea5a98a7335d7ad44be96fe76ca8eb2eaa76950eb8c989ebf2b78ec0": net/http: TLS handshake timeout.
See 'docker run --help'.

这时,需要把daemon.json文件里的信息改一下,改成国内阿里云镜像配置,可以提高拉取速度,避免超时问题,如下:

{"registry-mirrors": ["https://6kx4zyno.mirror.aliyuncs.com"],"insecure-registries": []
}

接着,重启systemctl restart docker,即可。

[root@192 opt]# sudo systemctl restart docker

再试着执行docker run hello-world,这次就正常了:

[root@192 opt]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:393b81f0ea5a98a7335d7ad44be96fe76ca8eb2eaa76950eb8c989ebf2b78ec0
Status: Downloaded newer image for hello-world:latest

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

查看一下是否已经成功下载hello-world镜像,可以看到,hello-world镜像已经被拉到了docker当中:

root@192 opt]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   40 hours ago    13.3kB
nginx         latest    f35646e83998   11 months ago   133MB
ubuntu        latest    549b9b86cb8d   21 months ago   64.2MB

相关文章

文章浏览阅读8.8k次,点赞2次,收藏7次。本文介绍Docker Com...
文章浏览阅读1.5w次,点赞7次,收藏76次。原网提供的教程需要...
文章浏览阅读940次,点赞20次,收藏20次。通过 docker run 命...
文章浏览阅读1k次,点赞20次,收藏20次。Podman 是一个开源的...
文章浏览阅读2.1k次。请注意,这些命令需要在 Docker 主机上...
文章浏览阅读1.1k次,点赞37次,收藏40次。nacos搭建集群连接...