CentOS 7 安装 docker-ce、Docker 程序环境 及 配置 Docker 镜像加速

1、CentOS 7 的默认 docker 版本

[root@Tang ~]# yum info docker
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Available Packages
Name        : docker
Arch        : x86_64
Epoch       : 2
Version     : 1.13.1
Release     : 103.git7f2769b.el7.centos
Size        : 18 M
Repo        : extras/7/x86_64
Summary     : Automates deployment of containerized applications
URL         : https://github.com/docker/docker
License     : ASL 2.0
Description : Docker is an open-source engine that automates the deployment of any
            : application as a lightweight, portable, self-sufficient container that will
            : run virtually anywhere.
            : 
            : Docker containers can encapsulate any payload, and will run consistently on
            : and between virtually any server. The same container that a developer builds
            : and tests on a laptop will run at scale, in production*, on VMs, bare-metal
            : servers, OpenStack clusters, public instances, or combinations of the above.

2、下载 docker-ce.repo

2.1 获取 docker-ce.repo 链接

在这里插入图片描述

2.2 在 CentOS 7 相关目录里进行此 repo 下载

[root@Tang ~]# cd /etc/yum.repos.d/
[root@Tang yum.repos.d]# pwd
/etc/yum.repos.d
[root@Tang yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
--2019-11-18 18:56:09--  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 27.221.92.7, 61.240.128.242, 119.167.132.16, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|27.221.92.7|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2640 (2.6K) [application/octet-stream]
Saving to: ‘docker-ce.repo’

100%[===========================================================================================>] 2,640       --.-K/s   in 0s      

2019-11-18 18:56:09 (39.5 MB/s) - ‘docker-ce.repo’ saved [2640/2640]

2.3 查看此 CentOS 的 repolist ,确认 repo 是否下载成功

[root@Tang yum.repos.d]# ll
total 48
-rw-r--r--. 1 root root 1664 Nov 23  2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Nov 23  2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Nov 23  2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Nov 23  2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Nov 23  2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Nov 23  2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 Nov 23  2018 CentOS-Vault.repo
-rw-r--r--. 1 root root 2640 Nov 17 15:51 docker-ce.repo
-rw-r--r--. 1 root root   91 Oct 16 17:01 epel.repo
-rw-r--r--. 1 root root 1050 Oct  3  2017 epel-testing.repo
-rw-r--r--. 1 root root  410 Aug 28  2017 zabbix.repo

2.4 此时查看 docker-ce 版本(建议安装此版本,此版本较新)

[root@Tang ~]# yum makecache
[root@Tang yum.repos.d]# yum info docker-ce 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Available Packages
Name        : docker-ce
Arch        : x86_64
Epoch       : 3
Version     : 19.03.5
Release     : 3.el7
Size        : 24 M
Repo        : docker-ce-stable/x86_64
Summary     : The open-source application container engine
URL         : https://www.docker.com
License     : ASL 2.0
Description : Docker is a product for you to build, ship and run any application as a
            : lightweight container.
            : 
            : Docker containers are both hardware-agnostic and platform-agnostic. This means
            : they can run anywhere, from your laptop to the largest cloud compute instance and
            : everything in between - and they don't require you to use a particular
            : language, framework or packaging system. That makes them great building blocks
            : for deploying and scaling web apps, databases, and backend services without
            : depending on a particular stack or provider.

2.4 docker-ce 生成的文件

[root@Tang ~]# rpm -ql docker-ce
/usr/bin/docker-init
/usr/bin/docker-proxy
/usr/bin/dockerd
/usr/lib/systemd/system/docker.service
/usr/lib/systemd/system/docker.socket
/var/lib/docker-engine/distribution_based_engine.json

3、安装并启动 docker-ce

3.1 安装

[root@Tang ~]# yum install docker-ce -y
Installed:
  docker-ce.x86_64 3:19.03.5-3.el7                                                                                                   

Dependency Installed:
  container-selinux.noarch 2:2.107-3.el7       containerd.io.x86_64 0:1.2.10-3.2.el7       docker-ce-cli.x86_64 1:19.03.5-3.el7      

Complete!
[root@Tang ~]# rpm -q docker-ce
docker-ce-19.03.5-3.el7.x86_64
[root@Tang ~]# rpm -ql docker-ce
/usr/bin/docker-init
/usr/bin/docker-proxy
/usr/bin/dockerd
/usr/lib/systemd/system/docker.service
/usr/lib/systemd/system/docker.socket
/var/lib/docker-engine/distribution_based_engine.json

3.2 启动

### 启动时使用的还是 docker 的 unit file ###
[root@Tang ~]# systemctl start docker
[root@Tang ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-11-19 09:38:34 CST; 3s ago
     Docs: https://docs.docker.com
 Main PID: 6437 (dockerd)
    Tasks: 12
   Memory: 44.5M
   CGroup: /system.slice/docker.service
           └─6437 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

3.3 运行程序环境

环境配置文件:
	## /etc/sysconfig/docker-network
    ## /etc/sysconfig/docker-storage
    ## /etc/sysconfig/docker

Unit File:
    ## /usr/lib/systemd/system/docker.service
        
Docker Registry配置文件:
    ## /etc/containers/registries.conf
            
docker-ce 配置文件:
    ## /etc/docker/daemon.json

4、配置 Docker 镜像加速

可以配置基于以下三个方式的 Docker 镜像加速,可以使用 , 分隔来进行多个镜像加速站点的配置:

  • docker cn
  • 阿里云加速器
  • 中国科技大学

4.1 docker cn 镜像加速配置

### docker cn 加速 ###
[root@Tang ~]# cat /etc/docker/daemon.json
{
	 "registry-mirrors": ["https://registry.docker-cn.com"]
}

4.2 阿里云镜像加速配置

4.2.1 获取阿里云镜像地址

阿里云 镜像服务器站点 链接

在这里插入图片描述

4.2.2 配置 /etc/docker/daemon.json 文件

[root@Tang ~]# cat /etc/docker/daemon.json
{
	 "registry-mirrors": ["https://pz88w5t4bz.mirror.aliyuncs.com"]
}
发布了158 篇原创文章 · 获赞 7 · 访问量 9747

猜你喜欢

转载自blog.csdn.net/weixin_44983653/article/details/103127950