centos安装docker-ce

xingyun86 2019-5-19 1564

Docker现在分为两个版本,Docker CE和Docker EE
其中Docker CE为开源版,Docker EE为企业版
本文为Docker CE的部署,环境为CentOS 7,VMware虚拟机一台(CentOS原生YUM源)
Docker官网  https://www.docker.com/
本文参考官方部署文档 https://docs.docker.com/install/linux/docker-ce/centos/#prerequisites

1.卸载旧版本(确保没有旧版本的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

yum报告没有安装以上软件即可
2.安装Docker CE
安装Docker的方法有三种,通过官方yum源进行安装、下载RPM包手动安装,使用一些脚本进行安装
在这里有正常联网能力的用户建议选择用官方yum源进行安装即可
首先安装存储驱动

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

下载官方yum源文件

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

(可选)启用边缘和测试存储库,通常是禁用状态,也可以选择启用

$ sudo yum-config-manager --enable docker-ce-edge
$ sudo yum-config-manager --enable docker-ce-test

如果启用后后悔的话可以使用以下命令禁用边缘和测试存储库

$ sudo yum-config-manager --disable docker-ce-edge

到这里就可以开始安装Docker CE了

$ sudo yum install docker-ce

到这里你也许会感觉到下载速度奇慢无比,但实际上也就是docker-ce-17.12.1.ce-1.el7.centos.x86_64.rpm这个文件下载缓慢
所以这里建议可以的话自己下载下来这个包进行安装会比较好一些

下载链接
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.12.1.ce-1.el7.centos.x86_64.rpm

另外关于Docker的版本号,2017年2月开始Docker官方启用了新的版本号规则,之前的1.12.6之类的停用,转而使用17.2.1这样的版本号,这个版本号的意思就是17年2月的第1个版本
所以可以的话请到官网查询当前最新版本号再进行下载,我这里部署时间为18年3月,当前最新版本号依然是17.12.1,即为17年12月发布的版本
$ yum -y install lrzsz
$ rz -E
$ yum -y install docker-ce-17.12.1.ce-1.el7.centos.x86_64.rpm

Complete!

在生产环境Docker官方建议安装特定版本的Docker CE,而不是始终使用最新版本
使用以下命令查看可用的版本

$ yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
已安装的软件包
可安装的软件包
 * updates: ap.stykers.moe
Loading mirror speeds from cached hostfile
 * extras: ap.stykers.moe
docker-ce.x86_64            3:18.09.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.6-3.el7                    @docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            18.06.3.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.2.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.3.ce-1.el7                   docker-ce-stable 
docker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable 
 * base: ap.stykers.moe

3.启动Docker

$ sudo systemctl start docker

4.验证安装是否正确

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:6f744a2005b12a704d2608d8070a494ad1145636eeb74a570c56b94d94ccdbfc
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镜像库中多了一个Hello-world,你的Docker容器库中也多了一个Hello-world

$ sudo docker image list
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        4 months ago        1.84kB
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
abf7940c3a8b        hello-world         "/hello"            6 minutes ago       Exited (0) 6 minutes ago                       trusting_montalcini

4.升级Docker CE

$ yum -y upgrade 你的新版本docker文件


×
打赏作者
最新回复 (0)
只看楼主
全部楼主
返回