• Docker (二): Docker安装及配置镜像加速


    一、 Docker 版本

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

    • community-edition 社区版
    • enterprise-edition 企业版 (收费)

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

    个人学习 Docker 使用 CE 社区版足够满足需求。
    在这里插入图片描述
    下载链接: https://docs.docker.com/get-docker/


    二、在 CentOS 上安装 Docker 引擎

    2.1、 系统要求

    官网提示如果要安装 Docker Engine,您需要一个 CentOS 7 以及以上的稳定版本,不支持或未测试存档版本。
    在这里插入图片描述


    2.2 、 卸载旧版本Docker

    较旧的Docker版本称为docker或docker-engine。 如果已安装这些程序,请卸载它们以及相关的依赖项。
    在这里插入图片描述

    sudo yum remove docker \
                    docker-client \
                    docker-client-latest \
                    docker-common \
                    docker-latest \
                    docker-latest-logrotate \
                    docker-logrotate \
                    docker-engine
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

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


    2.3 、设置 yum 源

    安装 yum-utils 软件包(提供了yum-config-manager程序)并设置稳定的 yum 源方便下载 Docker Engine。如果不设置yum源,那么每次都需要漂洋过海去下载文件,速度都非常慢。

    # 安装 yum-utilssudo 
    yum install -y yum-utils
    
    # 设置 yum 源为阿里云方便下载 
    Docker Enginesudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.4、Docker 安装

    安装最新版本的 Docker Engine 和容器

    sudo yum -y install docker-ce docker-ce-cli containerd.io
    
    • 1

    在这里插入图片描述

    安装过程中如果提示您接受 GPG 密钥,请验证指纹是否与 060A 61C5 1B55 8A7F 742B 77AAC52F EB6B 621E 9F35 匹配,如果是,输入y。如果不匹配这说明不是官方 Docker,仅作识别,没有多大意义,就算不一样,也可以输入 y


    三、 Docker 的启动与停止

    3.1、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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    3.2、安装效验

    # 查看版本
    docker -v
    
    # 查看详细版本
    docker version
    
    • 1
    • 2
    • 3
    • 4
    • 5

    四、 配置镜像加速

    Docker 从 Docker Hub 拉取镜像,因为是从国外获取,所以速度较慢,会出现以下情况:
    在这里插入图片描述
    可以通过配置国内镜像源的方式,从国内获取镜像,提高拉取速度。

    编辑文件daemon.json

    vi /etc/docker/daemon.json
    
    • 1

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

    {
         "registry-mirrors":["https://almtd3fa.mirror.aliyuncs.com"]
    }
    
    • 1
    • 2
    • 3

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

    # 重新加载某个服务的配置文件
    sudo systemctl daemon-reload
    
    # 重新启动 docker
    sudo systemctl restart docker
    
    • 1
    • 2
    • 3
    • 4
    • 5

    五、 测试拉取 hello-world 镜像并运行

    5.1、拉取运行 hello-world 镜像

    [root@localhost /]# docker run hello-world
    Unable to find image 'hello-world:latest' locally
    Trying to pull repository docker.io/library/hello-world ...
    latest: Pulling from docker.io/library/hello-world
    0e03bdcc26d7: Pull complete
    Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
    Status: Downloaded newer image for docker.io/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/
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    5.2、 docker run hello-world 运行流程

    在这里插入图片描述

  • 相关阅读:
    首家!亚信科技AntDB数据库完成中国信通院数据库迁移工具专项测试
    mysql连接查询
    Netty编解码器
    java 读取pdf文件内容
    Python从入门到入土-基本技能
    有趣的设计模式——解救抓狂的商场收银员
    22-07-05 七牛云存储图片、用户头像上传
    题目0117-斗地主2
    [设计模式]springboot优雅实现策略器模式(加入注册器实现)
    详解设计模式:组合模式
  • 原文地址:https://blog.csdn.net/haduwi/article/details/115035963