CentOS 安装 docker 并简单验证

CentOS 安装 docker 并简单验证

官方文档的参考安装手册:

https://docs.docker.com/v18.09/install/linux/docker-ce/centos/

https://docs.docker.com/engine/install/centos/

一、docker 的版本说明

docker 有以下两个版本:

社区版本(Community Edition,CE) ,即 docker CE 版本

企业版本(Enterprise Edition, EE) ,即 docker EE 版本

二、安装前说明

为了安装 docker 引擎,必须要 CentOS 7 以及以上版本。默认 centos-extras 仓库有比较老的 docker 的安装版本,不过一般不推荐生产用这么老的版本。推荐使用 overlay2 驱动引擎(至少用 CentOS 7.4以及之后的镜像就行,经过测试不打补丁,好像 CentOS 7.0,CentOS7.1,CentOS 7.2,CentOS 7.3 等都是用的 devicemapper 模拟实现)。关于驱动部分,这一部分涉及到底层镜像以及文件系统构建,会有专门的文档讲解。
我们这里打算使用阿里云的同步官方的 docker 镜像仓库后对开发者开放的 阿里云自己的 docker-ce 的仓库,并基于此仓库直接使用 yum 安装。先看一下 centos 自带的 extra 仓库的 docker 相关的包:

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
[root@localhost ~]# yum list all docker*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
docker.x86_64                                                                                                      2:1.13.1-109.gitcccb291.el7.centos                                                                                 extras
docker-client.x86_64                                                                                               2:1.13.1-109.gitcccb291.el7.centos                                                                                 extras
docker-client-latest.x86_64                                                                                        1.13.1-58.git87f2fab.el7.centos                                                                                    extras
docker-common.x86_64                                                                                               2:1.13.1-109.gitcccb291.el7.centos                                                                                 extras
docker-compose.noarch                                                                                              1.18.0-4.el7                                                                                                       epel  
docker-distribution.x86_64                                                                                         2.6.2-2.git48294d9.el7                                                                                             extras
docker-latest.x86_64                                                                                               1.13.1-58.git87f2fab.el7.centos                                                                                    extras
docker-latest-logrotate.x86_64                                                                                     1.13.1-58.git87f2fab.el7.centos                                                                                    extras
docker-latest-v1.10-migrator.x86_64                                                                                1.13.1-58.git87f2fab.el7.centos                                                                                    extras
docker-logrotate.x86_64                                                                                            2:1.13.1-109.gitcccb291.el7.centos                                                                                 extras
docker-lvm-plugin.x86_64                                                                                           2:1.13.1-109.gitcccb291.el7.centos                                                                                 extras
docker-novolume-plugin.x86_64                                                                                      2:1.13.1-109.gitcccb291.el7.centos                                                                                 extras
docker-registry.x86_64                                                                                             0.9.1-7.el7                                                                                                        extras
docker-v1.10-migrator.x86_64                                                                                       2:1.13.1-109.gitcccb291.el7.centos                                                                                 extra

新版的包现在都叫 docker-ce 了,因为一些历史竞争原因。然后阿里云的 docker 镜像库配置说明地址:

https://developer.aliyun.com/mirror/docker-ce

三、安装配置

3.1、配置 docker-ce 的仓库指向阿里云

我们不按照阿里云推荐的指令使用。我们直接去找到 repo 配置,下载到我们的服务器的对应目录。
https://mirrors.aliyun.com/docker-ce/linux/centos/
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

cd /etc/yum.repos.d && wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
我们可以看一下 docker-ce.repo 里面的 baseurl 是不是指向阿里云,如果是就忽略。
建议把 CentOS 的 base 仓库以及已经安装的 epel 仓库都指向阿里云的。(这部分我们不介绍)

3.2、查看仓库中 docker-ce 版本

[root@localhost ~]# yum list all docker-ce*
......
结果中显示的:
docker-ce 版本是 3:19.03.8-3.el7
docker-ce-cli 版本是 1:19.03.8-3.el7

yum list docker-ce* --showduplicates | sort -r
查看实际有哪些版本的包。

3.3、安装指定版本的包

$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

这里我们推荐生产大量使用的一个非最新的大版本。(往前推一个大版本,然后补丁版本的最新版本)
docker-ce 大版本: 18.09.9
docker-ce-cli 大版本的: 18.09.9

yum install docker-ce-18.09.9 docker-ce-cli-18.09.9

[root@localhost ~]# rpm -qa|grep docker-ce
docker-ce-cli-18.09.9-3.el7.x86_64
docker-ce-18.09.9-3.el7.x86_64

3.4、安装包以及安装主要文件

安装主要有三个包:
docker-ce
docker-ce-cli
containerd.io

docker-ce(服务端的包):
/usr/bin/docker-init
/usr/bin/docker-proxy
/usr/bin/dockerd-ce
/usr/lib/systemd/system/docker.service
/usr/lib/systemd/system/docker.socket

docker-ce-cli(主要是客户端组件相关的包,包括文档):
/usr/bin/docker
然后就是一些 man 手册。

containerd.io(比较底层的一些东西):
/usr/bin/runc
/usr/bin/containerd
/usr/lib/systemd/system/containerd.service

3.5、启动 docker-ce 容器的服务端程序

[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# systemctl status docker.service
[root@localhost ~]# systemctl enable docker.service #开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

3.6、简单查看


[root@localhost ~]# docker version
[root@localhost ~]# docker info

docker info 有归类于 docker 的 system,所以可以这样查看: docker system info
docker version 主要是用来查看版本信息。

docker version 输出内容: 
[root@localhost ~]# docker version
Client:  #客户端相关的版本信息
 Version:           18.09.9
 API version:       1.39
 Go version:        go1.11.13
 Git commit:        039a7df9ba
 Built:             Wed Sep  4 16:51:21 2019
 OS/Arch:           linux/amd64
 Experimental:      false   #是否是实验版本

Server: Docker Engine - Community
 Engine: #服务端相关的版本信息
  Version:          18.09.9
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.11.13
  Git commit:       039a7df
  Built:            Wed Sep  4 16:22:32 2019
  OS/Arch:          linux/amd64
  Experimental:     false  #是否是实验版本、
  
  docker system info 输出信息就有点多了,涉及的东西特别广,我这里简单罗列一下,不懂的可以先忽略:
  容器不同状态的数量
  镜像数
  服务端版本
  底层驱动
  底层文件系统
  一些加载驱动和名称空间的情况
  插件(容器,网络,日志)
  是否激活 swarm
  容器实现(新版一般都是 runC)
  内核版本
  操作系统
  系统架构,内存,cpu等
  docker的根目录(/var/lib/docker)
  还有什么镜像加速器,是否为实验版本标识,License等

docker system info 的一份参考输出:

[root@localhost ~]# docker system info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.09.9
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 3.10.0-1062.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: localhost.localdomain
ID: QMRY:YZZV:3G75:QNV4:D7FW:6VPT:Z5GM:2LVF:LTVC:J37D:QWRU:TVJ6
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章