Centos7.0安装docker全纪录(关键点:指定安装docker的版本,container-linux问题)

突出问题

1.关于centos7安装docker的文章比较多,但是按照这些教程往往不能正常运行docker,造成问题的主要是版本不兼容问题,centos7.x及6.x很多操作系统跟最新的docker版本(至少截止2019年)不兼容。

因此,必须指定安装兼容当前操作系统版本的docker。

2.在安装docker 时,报错 container-selinux >= 2.9, container-selinux无法直接用yum进行安装

安装过程

1. 通过 uname -r 命令查看当前操作系统内核版本,docker要求CentOS7的内核版本高于 3.10

uname -r

2.删除旧版本的docker

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

3.安装一些必要的系统工具

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

4.添加国内docker源

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

5.更新 yum 缓存:

sudo yum makecache fast

6.指定想要安装的版本,此时可使用如下命令列出当前可用的Docker版本。

sudo yum list docker-ce.x86_64  --showduplicates | sort -r

7.可使用如下命令,安装想要安装的Docker CE版本。

sudo yum install -y docker-ce-17.12.1.ce

8.安装时可能会出现以下错误

Error: Package: docker-ce-17.12.1.ce-1.el7.centos.x86_64 (docker-ce)
           Requires: container-selinux >= 2.9
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

 

container-selinux >= 2.9 

这个报错是container-selinux版本低或者是没安装的原因

yum 安装container-selinux 一般的yum源又找不到这个包

需要安装epel源 才能yum安装container-selinux

然后在安装docker-ce就可以了。

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

yum install epel-release  

yum install container-selinux

sudo yum install -y docker-ce-17.12.1.ce

9.启动 Docker 后台服务

sudo systemctl start docker

10.验证docker版本

[root@master ~]# docker version
Client:
 Version:       17.12.1-ce
 API version:   1.35
 Go version:    go1.9.4
 Git commit:    7390fc6
 Built: Tue Feb 27 22:15:20 2018
 OS/Arch:       linux/amd64

Server:
 Engine:
  Version:      17.12.1-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.9.4
  Git commit:   7390fc6
  Built:        Tue Feb 27 22:17:54 2018
  OS/Arch:      linux/amd64
  Experimental: false
[root@master ~]# rpm -qa docker*
docker-ce-17.12.1.ce-1.el7.centos.x86_64

11.运行hello-world

[root@master ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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/

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值