安装Docker(centos7)

一、安装前置条件

1.1 操作系统要求

安装Docker Engine,需要Centos7且内核版本在3.10以上版本。该centos-extras库必须启用,默认情况下,此存储库是启用的,如已禁用,则需要启用它。

查看当前内核版本:

uname -r

1.2 root登录,将yum包更新到最新

yum -y update

1.3 卸载旧版本docker

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

1.4 安装所需的软件包

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

1.5 设置yum源

官方源地址(比较慢):

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

 阿里云源:

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

 清华大学源:

yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

二、安装Docker Engine

2.1 安装最新版本的Docker Engine

yum install docker-ce docker-ce-cli containerd.io
或
yum install -y docker-ce

2.2 安装指定版本的Docker Engine

yum list docker-ce --showduplicates | sort -r
        docker-ce.x86_64            3:19.03.9-3.el7                    docker-ce-stable 
        docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable 
        docker-ce.x86_64            3:19.03.7-3.el7                    docker-ce-stable 
        docker-ce.x86_64            3:19.03.6-3.el7                    docker-ce-stable 
        docker-ce.x86_64            3:19.03.5-3.el7                    docker-ce-stable 
        docker-ce.x86_64            3:19.03.4-3.el7                    docker-ce-stable 
        docker-ce.x86_64            3:19.03.3-3.el7                    docker-ce-stable 
        docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable 
        docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable 
        docker-ce.x86_64            3:19.03.12-3.el7                   docker-ce-stable 
        docker-ce.x86_64            3:19.03.12-3.el7                   @docker-ce-stable

2.3 启动Docker

systemctl start docker

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

docker run hello-world

 运行成功:

    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/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 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/

 运行失败:

    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    0e03bdcc26d7: Pulling fs layer 
    docker: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/bf/bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b/data?verify=1596011879-aGOPb8c3qXZ1NaIw850GXq569U0%3D: dial tcp 104.18.123.25:443: i/o timeout.
    See 'docker run --help'.

 注意:出现以上错误信息,在/etc/resolv.conf文件中新增参数nameserver 8.8.8.8,修改完成后需重启Docker Engine 如下:

vi /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.189.2
nameserver 8.8.8.8

2.5 重启Docker Engine

service docker restart

2.6 设置docker开机启动

systemctl enable docker

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值