centos 7 Docker 安装及配置镜像加速

文章目录

  • centos 7 Docker 安装及配置镜像加速
    • Docker 版本
    • 基于 `CentOS `安装 `Docker` 引擎
    • 系统要求
    • 卸载旧版本
    • 检查是否能够上外网
    • 安装软件组
    • 设置yum源
      • 1. 备份yum源
      • 2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
      • 3.添加Docker Engine软件源信息
    • yum 安装 gcc 相关
    • 刷新 yum 源缓存
    • 为了方便我们可以更新一下系统
    • 安装需要的软件包
    • 更新 yum 软件包索引
    • 安装 Docker-ce
      • 注意
    • 安装完毕后启动
    • 开机自启动
    • 安装校验
    • 测试启动
    • docker 的停止、卸载、启动
    • 配置镜像加速
    • hello-world
    • 补充包(附赠宝典)

Docker 版本

随着 Docker 的飞速发展,企业级功能的上线,更好的服务意味着需要支付一定的费用,目前 Docker 被分为两个版本:

  • community-edition 社区版
  • enterprise-edition 企业版

Docker 企业版(EE)专为企业开发和 IT 团队设计,可在大规模生产中构建,运送和运行关键业务应用程序。Docker EE 集成,认证和支持,为企业提供业界最安全的容器平台,实现所有应用程序的现代化。作为一个以应用为中心的平台,Docker EE 旨在加速和保护整个软件供应链,从开发到在任何基础设施上运行的生产。

我们学习 Docker 使用 CE 社区版即可。

基于 CentOS安装 Docker 引擎

Docker 支持 Mac Windows Linux,本文使用 Linux 环境教大家如何基于 CentOS 安装 Docker 及配置镜像加速。

官方文档:https://docs.docker.com/

系统要求

官网提示如果要安装 Docker Engine,您需要一个 CentOS 7 以及以上的稳定版本。

1.查看centos系统内核版本

[root@Stupidkid ~]# uname -a
Linux Stupidkid 3.10.0-1160.2.2.el7.x86_64 #1 SMP Tue Oct 20 16:53:08 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

2.先确定是否 Centos 7及以上的版本

[root@Stupidkid ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

卸载旧版本

有比较旧的版本可以先卸载。较旧的 Docker 版本为 dockerdocker-engine。 如果已安装这些程序,请卸载它们以及相关的依赖项。

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

Docker 镜像、容器、数据卷和网络数据都保存在 /var/lib/docker/。新的 Docker 引擎包现在为 Docker-ce

检查是否能够上外网

[root@Stupidkid ~]# ping blog.taoxiaoxin.club
PING blog.taoxiaoxin.club (47.100.93.86) 56(84) bytes of data.
64 bytes from 47.100.93.86 (47.100.93.86): icmp_seq=1 ttl=53 time=4.34 ms
64 bytes from 47.100.93.86 (47.100.93.86): icmp_seq=2 ttl=53 time=5.49 ms
64 bytes from 47.100.93.86 (47.100.93.86): icmp_seq=3 ttl=53 time=4.49 ms
64 bytes from 47.100.93.86 (47.100.93.86): icmp_seq=4 ttl=53 time=4.32 ms

安装软件组

安装所需的基础软件

[root@Stupidkid yum.repos.d]# yum -y install tree nmap sysstat lrzsz dos2unix telnet bash-completion bash-completion-extras vim lsof net-tools rsync ntpdate nfs-utils wget[root@Stupidkid yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0   6296      0 --:--:-- --:--:-- --:--:--  6291

设置yum源

安装 yum-utils 软件包(提供了 yum-config-manager 程序)并设置稳定的 yum 源方便下载 Docker Engine。

1. 备份yum源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

3.添加Docker Engine软件源信息

# 安装 yum-utils
sudo yum install -y yum-utils
# 设置 yum 源为阿里云方便下载 Docker Engine
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum 安装 gcc 相关

[root@Stupidkid ~]# yum -y install gcc gcc-c++

刷新 yum 源缓存

[root@Stupidkid ~]# yum makecache

为了方便我们可以更新一下系统

[root@Stupidkid ~]# yum update
[root@Stupidkid ~]# yum update -y --exclud=kernel*

安装需要的软件包

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

更新 yum 软件包索引

yum makecache fast

安装 Docker-ce

yum -y install docker-ce

注意

# 注意:官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
# vim /etc/yum.repos.d/docker-ee.repo
#   将[docker-ce-test]下方的enabled=0修改为enabled=1
#
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
#   Loading mirror speeds from cached hostfile
#   Loaded plugins: branch, fastestmirror, langpacks
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            @docker-ce-stable
#   docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable
#   Available Packages
# Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
# sudo yum -y install docker-ce-[VERSION]

安装完毕后启动

sudo service docker start

开机自启动

[root@Stupidkid ~]# systemctl enable --now docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

安装校验

[root@Stupidkid ~]# docker -v
Docker version 19.03.14, build 5eb3275d40[root@Stupidkid ~]# docker version
Client: Docker Engine - CommunityVersion:           19.03.14API version:       1.40Go version:        go1.13.15Git commit:        5eb3275d40Built:             Tue Dec  1 19:20:42 2020OS/Arch:           linux/amd64Experimental:      falseServer: Docker Engine - CommunityEngine:Version:          19.03.14API version:      1.40 (minimum version 1.12)Go version:       go1.13.15Git commit:       5eb3275d40Built:            Tue Dec  1 19:19:17 2020OS/Arch:          linux/amd64Experimental:     falsecontainerd:Version:          1.3.9GitCommit:        ea765aba0d05254012b0b9e595e995c09186427frunc:Version:          1.0.0-rc10GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dddocker-init:Version:          0.18.0GitCommit:        fec3683

测试启动

[root@Stupidkid ~]# docker info
Client:Debug Mode: falseServer:Containers: 0Running: 0Paused: 0Stopped: 0Images: 0Server Version: 19.03.14Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: ea765aba0d05254012b0b9e595e995c09186427frunc version: dc9208a3303feef5b3839f4323d9beb36df0a9ddinit version: fec3683Security Options:seccompProfile: defaultKernel Version: 3.10.0-1160.2.2.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 468.4MiBName: StupidkidID: XN52:QGCZ:PTQF:J4PY:LCY6:GEQF:TYBT:C4WD:5PHM:7P3S:WLJT:IOTDDocker Root Dir: /var/lib/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries:127.0.0.0/8Live Restore Enabled: false

docker 的停止、卸载、启动

# 启动 docker
sudo systemctl start docker
# 停止 docker
sudo systemctl stop docker
# 重启 docker
sudo systemctl restart docker
# 设置开机启动
sudo systemctl enable docker
# 查看 docker 状态
sudo systemctl status docker
# 查看 docker 内容器的运行状态
sudo docker stats
# 查看 docker 概要信息
sudo docker info
# 查看 docker 帮助文档
sudo docker --help
# 卸载docker
yum -y remove docker-ce
# 强制卸载docker
rm -rf /var/lib/docker

配置镜像加速

Docker 从 Docker Hub 拉取镜像,因为是从国外获取,所以速度较慢,会出现以下情况:

[root@localhost ~]# 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/latest: net/http: TLS handshake timeout.
See 'docker run --help'.

可以通过配置国内镜像源的方式,从国内获取镜像,提高拉取速度。这里介绍中国科学技术大学(LUG@USTC)的开源镜像:https://docker.mirrors.ustc.edu.cn 和网易的开源镜像:http://hub-mirror.c.163.com

USTC 是老牌的 Linux 镜像服务提供者了,USTC 的 Docker 镜像加速服务速度很快。USTC 和网易的优势之一就是不需要注册,属于真正的公共服务。(也可以使用阿里等其他服务商的镜像加速服务)

编辑文件 daemon.json

vi /etc/docker/daemon.json

在文件中输入以下内容并保存。

{"registry-mirrors": ["http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn"]
}

重新加载配置信息及重启 Docker 服务。

# 重新加载某个服务的配置文件
sudo systemctl daemon-reload
# 重新启动 docker
sudo systemctl restart docker

hello-world

通过运行 hello-world 镜像来验证 Docker Engine 是否已正确安装。

[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally # 本地找不到 hello-world 镜像
latest: Pulling from library/hello-world # 拉取最新版本的 hello-world 镜像
0e03bdcc26d7: Pull complete
Digest: sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202
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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/

docker run hello-world 命令执行流程图如下。

补充包(附赠宝典)

阿里云Docker CE 镜像下载及安装文档:https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11QcVGnK

阿里云镜像站:https://developer.aliyun.com/mirror/

华为云镜像站:https://mirrors.huaweicloud.com/

清华云镜像站:https://mirrors.tuna.tsinghua.edu.cn/

centos 7 Docker 安装及配置镜像加速相关推荐

  1. Docker:docker简介及CentOS7安装Docker,以及配置镜像加速问题解决

    一.Docker是什么: 一款产品从开发到上线,从操作系统,到运行环境,再到应用配置.作为开发+运维之间的协作我们需要关心很多东西,这也是很多互联网公司都不得不面对的问题,特别是各种版本的迭代之后,不 ...

  2. Docker安装及配置镜像加速器

    一:简介 首先说明一下Docker是什么,可以做什么. Docker是一个开源的容器引擎,可将应用程序和基础设施层隔离,并且能将基础设施当作程序一样进行管理. Docker可更快地打包.测试以及部署应 ...

  3. Docker安装及配置镜像加速器(一)

    一:简介 首先说明一下Docker是什么,可以做什么. Docker是一个开源的容器引擎,可将应用程序和基础设施层隔离,并且能将基础设施当作程序一样进行管理. Docker可更快地打包.测试以及部署应 ...

  4. docker安装部署dragonfly2镜像加速服务

    Dragonfly安装部署文档 ​ Dragonfly 作为龙蜥社区的镜像加速标准解决方案,是一款基于 P2P 的智能镜像和文件分发工具.它旨在提高大规模文件传输的效率和速率,最大限度地利用网络带宽. ...

  5. Windows安装docker,和配置镜像加速地址

    https://www.runoob.com/docker/windows-docker-install.html 我的是win10家庭版10.0.14393 ,版本不够,得用toolbox安装. 在 ...

  6. centos7安装docker并配置镜像加速

    Centos7安装docker 并配置镜像加速 1.如果系统上之前有安装过docker 那么就需要先执行下面的命令 删除旧版本docker sudo yum remove docker \docker ...

  7. 腾讯云轻量应用服务器如何安装 Docker 并配置镜像加速源?

    本文指导您如何在轻量应用服务器上安装 Docker,以及使用 Docker 镜像源加速镜像下载. 在轻量应用服务器中安装 Docker 请根据实例的操作系统类型,参考相应的文档进行安装. 操作系统 说 ...

  8. centos7 快速安装docker和配置镜像加速

    按照官方文档来一步步进行 Install Docker Engine on CentOS | Docker Documentation 1:先卸载旧版本内容 sudo yum remove docke ...

  9. Windows 10安装Docker以及配置镜像加速

    Windows 10安装Docker以及配置镜像加速 一 环境检查 1.1 检查是否开启虚拟化 1.2 开启Hyper-V服务 二 下载安装Docker 2.1 安装前配置安装目录 2.2 进入阿里云 ...

最新文章

  1. Linux小工具(3)之/proc目录详细介绍(上)
  2. 如何使用纯 CSS 创建翻牌动画
  3. ElasticSearch Java Api(四) -删除索引
  4. Wow,一个免费、不怕打的评论插件!
  5. 2021牛客暑期多校训练营7 xay loves trees dfs序 + 主席树
  6. 基于python渗透测试_Python中基于属性的测试简介
  7. Windows IIS 日志分析研究(Log Parser Log Parser Lizard Log Parser Studio) update...
  8. java演练 类与对象 给我一个数字还你一个字符串
  9. 矢量素材 |企业商务画册设计参考
  10. VS-watch窗口
  11. 聚焦BCS|新华财经:奇安信董事长齐向东:网络安全市场规模10年将增长10倍
  12. .NET Core跨平台部署
  13. Ubuntu17.10下安装TIM
  14. 著名游戏引擎及其开发游戏
  15. 【愚公系列】2022年10月 微信小程序-电商项目-收货地址功能实现
  16. 绿盟科技实习安服面经
  17. vue报错“NavigationDuplicat: Avoided redundant navigation to current location”解决方法
  18. C#Skip和Take的用法
  19. 代码重构(一)原理和规范
  20. 用python动态时钟代码_python实现简易动态时钟

热门文章

  1. 爬虫python下载文献代码_Python爬虫案例:爬取微信公众号文章
  2. 记一次磁盘扩容失败并恢复
  3. Delphi 获取其他程序窗口句柄
  4. 能在学生用计算机的面上画的图画,学生作品之一《学生电脑绘画》(图文)
  5. 西门子1200与欧姆龙E5cc温控器 远程+本地双重控制通讯程序
  6. 伤脑筋十二块游戏程序设计制作
  7. 单线程读单线程写一个变量是否一定要加锁
  8. 管理员发送系统公告,每个用户登陆可查看自己的已读和未读状态的公告
  9. 迅为RK3399开发板瑞芯微64位六核Linux安卓8.1系统
  10. 生源985占比100%,北大叉院这个专业本校学生也心仪~