centos7安装docker
一:环境准备
https://docs.docker.com/install/linux/docker-ce/centos/
如果无法拉取镜像,修改DNS:加入8.8.8.8
1.1:删除旧版本的docker
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
1.2:从库安装
https://docs.docker.com/install/linux/docker-ce/centos/#install-using-the-repository
https://download.docker.com/linux/centos/docker-ce.repo
1.2.1:安装所需的包
yum install -y yum-utils \ device-mapper-persistent-data \ lvm2
1.2.2:设置repo库
sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
1.2.3:列出库中版本
yum list docker-ce --showduplicates | sort -r
[root@docker-01 zm]# yum list docker-ce --showduplicates | sort -r 已加载插件:fastestmirror 可安装的软件包 * updates: mirrors.cn99.com Loading mirror speeds from cached hostfile * extras: mirrors.zju.edu.cn 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: mirrors.cn99.com
1.2.4:安装 yum install docker-ce
[root@docker-01 zm]# yum install docker-ce 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.cn99.com * extras: mirrors.zju.edu.cn * updates: mirrors.cn99.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 docker-ce.x86_64.3.18.09.3-3.el7 将被 安装 --> 正在处理依赖关系 containerd.io >= 1.2.2-3,它被软件包 3:docker-ce-18.09.3-3.el7.x86_64 需要 --> 正在处理依赖关系 docker-ce-cli,它被软件包 3:docker-ce-18.09.3-3.el7.x86_64 需要 --> 正在检查事务 ---> 软件包 containerd.io.x86_64.0.1.2.4-3.1.el7 将被 安装 ---> 软件包 docker-ce-cli.x86_64.1.18.09.3-3.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ============================================================================================================ Package 架构 版本 源 大小 ============================================================================================================ 正在安装: docker-ce x86_64 3:18.09.3-3.el7 docker-ce-stable 19 M 为依赖而安装: containerd.io x86_64 1.2.4-3.1.el7 docker-ce-stable 22 M docker-ce-cli x86_64 1:18.09.3-3.el7 docker-ce-stable 14 M 事务概要 ============================================================================================================ 安装 1 软件包 (+2 依赖软件包) 总下载量:55 M 安装大小:236 M Is this ok [y/d/N]: y Downloading packages: 警告:/var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.2.4-3.1.el7.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 621e9f35: NOKEY containerd.io-1.2.4-3.1.el7.x86_64.rpm 的公钥尚未安装 (1/3): containerd.io-1.2.4-3.1.el7.x86_64.rpm | 22 MB 00:00:03 (2/3): docker-ce-cli-18.09.3-3.el7.x86_64.rpm | 14 MB 00:00:03 (3/3): docker-ce-18.09.3-3.el7.x86_64.rpm | 19 MB 00:02:11 ------------------------------------------------------------------------------------------------------------ 总计 428 kB/s | 55 MB 00:02:11 从 https://download.docker.com/linux/centos/gpg 检索密钥 导入 GPG key 0x621E9F35: 用户ID : "Docker Release (CE rpm) <docker@docker.com>" 指纹 : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35 来自 : https://download.docker.com/linux/centos/gpg 是否继续?[y/N]:y Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : 1:docker-ce-cli-18.09.3-3.el7.x86_64 1/3 正在安装 : containerd.io-1.2.4-3.1.el7.x86_64 2/3 正在安装 : 3:docker-ce-18.09.3-3.el7.x86_64 3/3 验证中 : 3:docker-ce-18.09.3-3.el7.x86_64 1/3 验证中 : containerd.io-1.2.4-3.1.el7.x86_64 2/3 验证中 : 1:docker-ce-cli-18.09.3-3.el7.x86_64 3/3 已安装: docker-ce.x86_64 3:18.09.3-3.el7 作为依赖被安装: containerd.io.x86_64 0:1.2.4-3.1.el7 docker-ce-cli.x86_64 1:18.09.3-3.el7 完毕!
1.2.5:添加开机启动
systemctl status docker
systemctl status docker
systemctl enable docker
1.2.6:docker version
[root@docker-01 zm]# docker version Client: Version: 18.09.3 API version: 1.39 Go version: go1.10.8 Git commit: 774a1f4 Built: Thu Feb 28 06:33:21 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.3 API version: 1.39 (minimum version 1.12) Go version: go1.10.8 Git commit: 774a1f4 Built: Thu Feb 28 06:02:24 2019 OS/Arch: linux/amd64 Experimental: false
1.3:用rpm包方法安装docker
从文件安装
https://docs.docker.com/install/linux/docker-ce/centos/#install-from-a-package
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm yum install /zz/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
已安装:
docker-ce.x86_64 0:18.03.1.ce-1.el7.centos
作为依赖被安装:
audit-libs-python.x86_64 0:2.8.4-4.el7 checkpolicy.x86_64 0:2.5-8.el7
container-selinux.noarch 2:2.74-1.el7 libcgroup.x86_64 0:0.41-20.el7
libsemanage-python.x86_64 0:2.5-14.el7 libtool-ltdl.x86_64 0:2.4.2-22.el7_3
pigz.x86_64 0:2.3.3-1.el7.centos policycoreutils-python.x86_64 0:2.5-29.el7_6.1
python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7
完毕!
1.3.1:运行hello-world:报错无法拉取镜像
[root@docker-01 zm]# docker run hello-world Unable to find image 'hello-world:latest' locally docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: net/http: TLS handshake timeout. See 'docker run --help'.
修改DNS:加入8.8.8.8
[root@docker-01 zm]# 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/ [root@docker-01 zm]#