版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mwb2001/article/details/89637011
一、Docker说明
从 2017 年 3 月开始 docker 在原来的基础上分为两个分支版本: Docker CE 和 Docker EE。
Docker CE 即社区免费版,Docker EE 即企业版,强调安全,但需付费使用。
本文介绍 Docker CE 的安装使用。
二、CentOS搭建
三、Docker安装
1、前提要求
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
查看内核版本
uname -r
2、使用 yum 安装
移除旧的版本:
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
安装一些必要的系统工具:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
离线安装 yum-utils (有时候下载不了,可以进行离线下载安装)
http://yum.baseurl.org/download/yum-utils/
[root@DockerVM ~]# ls
anaconda-ks.cfg python-chardet-2.2.1-1.el7_1.noarch.rpm python-kitchen-1.1.1-5.el7.noarch.rpm rpmbuild yum-utils-1.1.31-50.el7.noarch.rpm
[root@DockerVM ~]# rpm -ivh python-chardet-2.2.1-1.el7_1.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:python-chardet-2.2.1-1.el7_1 ################################# [100%]
[root@DockerVM ~]# rpm -ivh python-kitchen-1.1.1-5.el7.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:python-kitchen-1.1.1-5.el7 ################################# [100%]
[root@DockerVM ~]# rpm -ivh yum-utils-1.1.31-50.el7.noarch.rpm
error: Failed dependencies:
libxml2-python is needed by yum-utils-1.1.31-50.el7.noarch
[root@DockerVM ~]# ls
anaconda-ks.cfg libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm python-chardet-2.2.1-1.el7_1.noarch.rpm python-kitchen-1.1.1-5.el7.noarch.rpm rpmbuild yum-utils-1.1.31-50.el7.noarch.rpm
[root@DockerVM ~]# rpm -ivh libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:libxml2-python-2.9.1-6.el7_2.3 ################################# [100%]
[root@DockerVM ~]# rpm -ivh yum-utils-1.1.31-50.el7.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:yum-utils-1.1.31-50.el7 ################################# [100%]
[root@DockerVM ~]#
添加软件源信息:(yum-utils 包含了 yum-config-manager)执行这步骤会下载docker-ce.repo,需要联网,一般配置为dhcp自动获取IP就行
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@DockerVM yum.repos.d]# sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
更新 yum 缓存:
sudo yum makecache fast
[root@DockerVM yum.repos.d]# sudo yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.njupt.edu.cn
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.nwsuaf.edu.cn
http://mirrors.cqu.edu.cn/CentOS/7.6.1810/os/x86_64/repodata/repomd.xml: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
Trying other mirror.
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): docker-ce-stable/x86_64/primary_db | 27 kB 00:00:00
(2/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00
Metadata Cache Created
-->备注:以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
安装 Docker-ce:
sudo yum -y install docker-ce
[root@DockerVM ~]# sudo yum -y install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.njupt.edu.cn
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.nwsuaf.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:18.09.5-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.5-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-18.09.5-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-18.09.5-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-18.09.5-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.74-1.el7 will be installed
--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.74-1.el7.noarch
---> Package containerd.io.x86_64 0:1.2.5-3.1.el7 will be installed
---> Package docker-ce-cli.x86_64 1:18.09.5-3.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-20.el7 will be installed
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.5-29.el7_6.1 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.4-4.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================================
Installing:
docker-ce x86_64 3:18.09.5-3.el7 docker-ce-stable 19 M
Installing for dependencies:
audit-libs-python x86_64 2.8.4-4.el7 base 76 k
checkpolicy x86_64 2.5-8.el7 base 295 k
container-selinux noarch 2:2.74-1.el7 extras 38 k
containerd.io x86_64 1.2.5-3.1.el7 docker-ce-stable 22 M
docker-ce-cli x86_64 1:18.09.5-3.el7 docker-ce-stable 14 M
libcgroup x86_64 0.41-20.el7 base 66 k
libsemanage-python x86_64 2.5-14.el7 base 113 k
policycoreutils-python x86_64 2.5-29.el7_6.1 updates 456 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.8-4.el7 base 620 k
Transaction Summary
============================================================================================================================================================================================================================
Install 1 Package (+10 Dependent packages)
Total download size: 57 M
Installed size: 241 M
Downloading packages:
(1/11): audit-libs-python-2.8.4-4.el7.x86_64.rpm | 76 kB 00:00:00
(2/11): container-selinux-2.74-1.el7.noarch.rpm | 38 kB 00:00:00
(3/11): checkpolicy-2.5-8.el7.x86_64.rpm | 295 kB 00:00:01
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.2.5-3.1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY ] 3.8 MB/s | 34 MB 00:00:05 ETA
Public key for containerd.io-1.2.5-3.1.el7.x86_64.rpm is not installed
(4/11): containerd.io-1.2.5-3.1.el7.x86_64.rpm | 22 MB 00:00:08
(5/11): libsemanage-python-2.5-14.el7.x86_64.rpm | 113 kB 00:00:00
(6/11): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00:00
(7/11): libcgroup-0.41-20.el7.x86_64.rpm | 66 kB 00:00:00
(8/11): setools-libs-3.3.8-4.el7.x86_64.rpm | 620 kB 00:00:00
(9/11): policycoreutils-python-2.5-29.el7_6.1.x86_64.rpm | 456 kB 00:00:02
(10/11): docker-ce-cli-18.09.5-3.el7.x86_64.rpm | 14 MB 00:00:03
(11/11): docker-ce-18.09.5-3.el7.x86_64.rpm | 19 MB 00:00:13
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 4.1 MB/s | 57 MB 00:00:13
Retrieving key from https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <[email protected]>"
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : libcgroup-0.41-20.el7.x86_64 1/11
Installing : setools-libs-3.3.8-4.el7.x86_64 2/11
Installing : audit-libs-python-2.8.4-4.el7.x86_64 3/11
Installing : checkpolicy-2.5-8.el7.x86_64 4/11
Installing : python-IPy-0.75-6.el7.noarch 5/11
Installing : libsemanage-python-2.5-14.el7.x86_64 6/11
Installing : policycoreutils-python-2.5-29.el7_6.1.x86_64 7/11
Installing : 2:container-selinux-2.74-1.el7.noarch 8/11
Installing : containerd.io-1.2.5-3.1.el7.x86_64 9/11
Installing : 1:docker-ce-cli-18.09.5-3.el7.x86_64 10/11
Installing : 3:docker-ce-18.09.5-3.el7.x86_64 11/11
Verifying : 1:docker-ce-cli-18.09.5-3.el7.x86_64 1/11
Verifying : libcgroup-0.41-20.el7.x86_64 2/11
Verifying : containerd.io-1.2.5-3.1.el7.x86_64 3/11
Verifying : policycoreutils-python-2.5-29.el7_6.1.x86_64 4/11
Verifying : libsemanage-python-2.5-14.el7.x86_64 5/11
Verifying : python-IPy-0.75-6.el7.noarch 6/11
Verifying : 3:docker-ce-18.09.5-3.el7.x86_64 7/11
Verifying : checkpolicy-2.5-8.el7.x86_64 8/11
Verifying : 2:container-selinux-2.74-1.el7.noarch 9/11
Verifying : audit-libs-python-2.8.4-4.el7.x86_64 10/11
Verifying : setools-libs-3.3.8-4.el7.x86_64 11/11
Installed:
docker-ce.x86_64 3:18.09.5-3.el7
Dependency Installed:
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 containerd.io.x86_64 0:1.2.5-3.1.el7 docker-ce-cli.x86_64 1:18.09.5-3.el7
libcgroup.x86_64 0:0.41-20.el7 libsemanage-python.x86_64 0:2.5-14.el7 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
Complete!
启动 Docker 后台服务
sudo systemctl start docker
检查Docker安装结果 hello-world
docker run hello-world
由于本地没有hello-world这个镜像,所以会下载一个hello-world的镜像,并在容器内运行。