Centos7 下安装 最新版docker

1. root账户登录,查看内核版本如下

uname -a

2.我是虚拟机装的Centos7,linux 3.10 内核

[root@localhost ~]# uname -a

Linux localhost.localdomain 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

3.把yum包更新到最新

yum update


[root@localhost ~]# yum update
已加载插件:fastestmirror
Determining fastest mirrors
 * base: mirrors.cqu.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.neusoft.edu.cn
base                                                                              | 3.6 kB  00:00:00     
extras                                                                            | 2.9 kB  00:00:00     
updates                                                                           | 2.9 kB  00:00:00     
(1/4): extras/7/x86_64/primary_db                                                 | 159 kB  00:00:00     
(2/4): base/7/x86_64/group_gz                                                     | 165 kB  00:00:00     
(3/4): base/7/x86_64/primary_db                                                   | 6.0 MB  00:00:03     
(4/4): updates/7/x86_64/primary_db                                                | 6.7 MB  00:00:09     
正在解决依赖关系
--> 正在检查事务
---> 软件包 NetworkManager.x86_64.1.1.18.0-5.el7 将被 升级
---> 软件包 NetworkManager.x86_64.1.1.18.0-5.el7_7.2 将被 更新
(期间要选择确认,输入 y 即可)

4.卸载旧版本(如果安装过旧版本的话)

yum list installed | grep docker

5.若是有的话,卸载docker,卸载命令如下

yum -y remove docker docker-common docker-selinux docker-engine

  (旧版名称是docker , 最新社区版 docker-engine, 目前已改名为docker-ce ) 

6. 安装需要的软件包

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



[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cqu.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.neusoft.edu.cn
软件包 device-mapper-persistent-data-0.8.5-1.el7.x86_64 已安装并且是最新版本
软件包 7:lvm2-2.02.185-2.el7_7.2.x86_64 已安装并且是最新版本
正在解决依赖关系
--> 正在检查事务
---> 软件包 yum-utils.noarch.0.1.1.31-52.el7 将被 安装
--> 正在处理依赖关系 python-kitchen,它被软件包 yum-utils-1.1.31-52.el7.noarch 需要
--> 正在处理依赖关系 libxml2-python,它被软件包 yum-utils-1.1.31-52.el7.noarch 需要

7.添加docker的yum源

选择其中一个命令执行

yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(中央仓库)

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库)

使用中央仓库,出现以下内容,表示安装成功

[root@localhost ~]# yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
已加载插件:fastestmirror
adding repo from: http://download.docker.com/linux/centos/docker-ce.repo
grabbing file http://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

此处可能会报错 (原因是国内访问不到docker官方镜像的缘故),那就使用阿里仓库(第二个命令)

 [Errno 14] curl#35 - "TCP connection reset by peer

8.查看所有仓库中所有docker版本,并选择特定版本安装

yum list docker-ce --showduplicates | sort -r


[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
已安装的软件包
可安装的软件包
 * updates: mirrors.neusoft.edu.cn
Loading mirror speeds from cached hostfile
 * extras: mirrors.ustc.edu.cn
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.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.7-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.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: mirrors.cqu.edu.cn

9.配置镜像加速器

(必须要配置,否则会出现访问镜像并不稳定 ,而且下载缓慢等问题)

注册阿里云账号 ,登陆该网址自行注册 ( https://www.aliyun.com/?utm_content=se_1010377 )

在这里插入图片描述

10.进入阿里云控制台如图

​​​​​​​​在这里插入图片描述

11.执行命令以下3条命令

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["输入自己的加速器地址"]}
EOF
systemctl daemon-reload

结果如下

在这里插入图片描述

13.安装Docker

yum install docker-ce (这样写默认安装最新版本)
yum install  docker-ce-<VERSION_STRING> (指定安装版本) 

执行如下命令

yum install docker-ce-18.03.1.ce

(此处若报错,一般还是无法官方镜像,请检查上一步文件中字母是否有错误)

安装成功,如下

[root@localhost ~]# yum install docker-ce-18.03.1.ce
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cqu.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.neusoft.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.0.18.03.1.ce-1.el7.centos 将被 安装
--> 正在处理依赖关系 libseccomp >= 2.3,它被软件包 docker-ce-18.03.1.ce-1.el7.centos.x86_64 需要
--> 正在处理依赖关系 container-selinux >= 2.9,它被软件包 docker-ce-18.03.1.ce-1.el7.centos.x86_64 需要
--> 正在处理依赖关系 pigz,它被软件包 docker-ce-18.03.1.ce-1.el7.centos.x86_64 需要
--> 正在处理依赖关系 libcgroup,它被软件包 docker-ce-18.03.1.ce-1.el7.centos.x86_64 需要
--> 正在处理依赖关系 libltdl.so.7()(64bit),它被软件包 docker-ce-18.03.1.ce-1.el7.centos.x86_64 需要
--> 正在处理依赖关系 libseccomp.so.2()(64bit),它被软件包 docker-ce-18.03.1.ce-1.el7.centos.x86_64 需要
--> 正在检查事务

14.启动并加入开机启动

systemctl start docker    (重启命令     systemctl restart docker) 

systemctl enable docker   (开机启动)

docker version            (查看docker版本号)

结果如下

[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# docker version
Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:20:16 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm
Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:23:58 2018
  OS/Arch:      linux/amd64
  Experimental: false

15.验证是否安装成功

docker run hello-world 

结果如下

[root@localhost ~]# docker run hello-world 
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
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已经安装成功了 。

接下来我们就可以访问并下载你所需要的镜像,或者使用dockerfile自行构建Docker镜像,部署安装你的应用程序到docker容器中了。

16.查看docker的状态

service docker status

结果如下

[root@centos7-00 ~]# service docker status
Redirecting to /bin/systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2020-02-16 16:54:35 CST; 10min ago
     Docs: https://docs.docker.com
 Main PID: 1093 (dockerd)
    Tasks: 18
   Memory: 128.3M
   CGroup: /system.slice/docker.service
           ├─1093 /usr/bin/dockerd
           └─2418 docker-containerd --config /var/run/docker/containerd/containerd.toml
2月 16 16:54:33 centos7-00 dockerd[1093]: time="2020-02-16T16:54:33+08:00" level=info msg="contai...nerd
2月 16 16:54:33 centos7-00 dockerd[1093]: time="2020-02-16T16:54:33.840191618+08:00" level=info m...ay2"
2月 16 16:54:34 centos7-00 dockerd[1093]: time="2020-02-16T16:54:34.089454686+08:00" level=info m...nds"
2月 16 16:54:34 centos7-00 dockerd[1093]: time="2020-02-16T16:54:34.091321598+08:00" level=info m...rt."
2月 16 16:54:35 centos7-00 dockerd[1093]: time="2020-02-16T16:54:35.298481220+08:00" level=info m...ess"
2月 16 16:54:35 centos7-00 dockerd[1093]: time="2020-02-16T16:54:35.627563756+08:00" level=info m...ne."
2月 16 16:54:35 centos7-00 dockerd[1093]: time="2020-02-16T16:54:35.928880127+08:00" level=info m...1-ce
2月 16 16:54:35 centos7-00 dockerd[1093]: time="2020-02-16T16:54:35.952860792+08:00" level=info m...ion"
2月 16 16:54:35 centos7-00 dockerd[1093]: time="2020-02-16T16:54:35.986619303+08:00" level=info m...ock"
2月 16 16:54:35 centos7-00 systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

17.停止docker

service docker stop
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

《小书生》

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值