Centos7 -Docker安装以及出现问题解决

前提

首先,你的Centos的系统一定要是64位的,不管版本是什么。并且内核版本至少是3.10以上。
用以下命令去查看你的内核版本:

$ uname -r
3.10.0-229.el7.x86_64

用yum安装

用具有sudo或者root权限的用户登录系统。
确保你的yum包已经更新。

$ sudo yum update

添加yum仓库

$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
添加如下内容:

[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

结束回车即可

安装Docker包

$ sudo yum install docker-engine

镜像加速

鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,我们可以需要配置加速器来解决,我使用的是阿里的镜像地址:

在/etc/docker/daemon.json文件中添加如下内容.

{

"registry-mirrors": ["https://wghlmi3i.mirror.aliyuncs.com"]

}

或者使用如下地址

{

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

}

启动 Docker 后台服务

[root@docker-node1 ~]# systemctl start docker.service

到此,docker 在 CentOS 系统的安装完成。

验证是否成功:
[root@dtc ~]# docker version
Client:
Version: 18.09.5
API version: 1.39
Go version: go1.10.8
Git commit: e8ff056
Built: Thu Apr 11 04:43:34 2019
OS/Arch: linux/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 18.09.5
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: e8ff056
Built: Thu Apr 11 04:13:40 2019
OS/Arch: linux/amd64
Experimental: false
[root@dtc ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@dtc ~]#
[root@dtc ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e
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/

[root@dtc ~]#

[root@dtc ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest fce289e99eb9 3 months ago 1.84kB
[root@dtc ~]#
此处hello-world已经出现,成功。

安装遇到的问题:
centos7安装docker出现Cannot connect to the Docker daemon at tcp://0.0.0.0:2375. Is the docker dae...

管理端口在 /lib/systemd/system/docker.service 文件中
将其中的 ExecStart=/usr/bin/dockerd 替换为:

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -H tcp://0.0.0.0:7654
(此处默认2375为主管理端口,unix:///var/run/docker.sock用于本地管理,7654是备用的端口)

将管理地址写入 /etc/profile   

echo 'export DOCKER_HOST=tcp://0.0.0.0:2375' >> /etc/profile

使profile生效

如果出现:Warning: docker.service changed on disk. Run 'systemctl daemon-reload' to reload units.

根据提示执行:systemctl daemon-reload
然后重启:systemctl restart docker.service

你可能感兴趣的:(Centos7 -Docker安装以及出现问题解决)