CentOS 7 安装 Docker-CE 并配置阿里云加速器

环境:CentOS 7.9 64bit

官方安装文档

官方安装文档:https://docs.docker.com/install/linux/docker-ce/centos/

卸载机器上的老版本

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

如果你机器上有安装过 Docker 的话, /var/lib/docker/ 目录会被保留下来。

安装 Docker

有两种安装方式:一种是yum安装,另一种是下载软件包安装,这里只介绍yum安装方式。

1) 安装所需软件包

yum install -y yum-utils

2) 配置稳定的仓库

官方:

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

国内推荐使用:

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3) 安装 Docker

yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

4) 启动 Docker

# 启动:
systemctl start docker
# 停止:
systemctl stop docker
# 重启:
systemctl restart docker
# 开机启动:
systemctl enable docker

5) 测试是否安装成功

a. 通过 docker version 查看docker版本信息

[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.12
 Git commit:        e91ed57
 Built:             Mon Dec 13 11:45:41 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.12
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.12
  Git commit:       459d0df
  Built:            Mon Dec 13 11:44:05 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

b. 通过运行 Docker 测试容器 hello-world 查看: docker run hello-world

[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:97a379f4f88575512824f3b352bc03cd75e239179eea0fecc38e597b2209f49a
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/

成功。

配置阿里云加速器

根据默认的配置,我们获取镜像都是要到docker官方的镜像仓库去拉取,由于国内网络原因,获取镜像速度很慢,所以这里我们配置阿里云加速器。

  1. 登录阿里云控制台,找到“容器镜像服务”,首次进去会提示你设置Registry登录密码,按照要求设置即可;

  2. 完成之后依次点击 “镜像工具-镜像加速器” 即可查看到你的加速器地址,以及在不同操作系统上的配置方法;

  3. 在CentOS上配置加速器:

    您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器,以下是我的加速器地址,请注意修改为你自己的。

    sudo mkdir -p /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
     "registry-mirrors": ["https://cvy84kji.mirror.aliyuncs.com"]
    }
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker
  4. 查看是否成功

    通过 docker info 即可查看到尾部有 Registry Mirrors .

    [root@localhost ~]# docker info |tail -10
    Debug Mode: false
    Registry: https://index.docker.io/v1/
    Labels:
    Experimental: false
    Insecure Registries:
     127.0.0.0/8
    Registry Mirrors:
     https://cvy84kji.mirror.aliyuncs.com/
    Live Restore Enabled: false

版权声明:
作者:admin
链接:https://www.chenxie.net/archives/2209.html
来源:蜀小陈
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭
目 录