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/

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章