Devops(二):CentOS7(在线)安装Docker
安装环境:
Centos7.5
从 2017 年 3 月开始 docker 在原来的基础上分为两个分支版本: Docker CE 和 Docker EE。
1)Docker CE 即社区免费版
2)Docker EE 即企业版,强调安全,但需付费使用。
本文介绍 Docker CE 的安装使用。
1)移除旧的版本
查询当前的Docker版本
$ docker -v
如果存在已安装的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
注意:卸载后,/var/lib/docker/ 下内容(images, containers, volumes,networks)依然被保留。
执行示例:
[root@master devops]# 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
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-selinux
No Match for argument: docker-engine-selinux
No Match for argument: docker-engine
No Packages marked for removal
备注:因为之前这台服务器未安装过docker,因此会提示找不到。
2)配置库
3.1)安装所需的软件包 yum-utils、device-mapper-persistent-data和 lvm2
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
执行示例:
[root@master devops]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
: Timeout on http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
* base: mirrors.huaweicloud.com
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
base | 3.6 kB ::
bintray--sbt-rpm | 1.3 kB ::
http://mirrors.cn99.com/centos/7.5.1804/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
mysql-connectors-community | 2.5 kB ::
mysql-tools-community | 2.5 kB ::
mysql57-community | 2.5 kB ::
updates | 3.4 kB ::
(/): base//x86_64/group_gz | kB ::
(/): mysql-tools-community/x86_64/primary_db | kB ::
(/): bintray--sbt-rpm/primary | 4.2 kB ::
(/): mysql-connectors-community/x86_64/primary_db | kB ::
(/): mysql57-community/x86_64/primary_db | kB ::
(/): base//x86_64/primary_db | 6.0 MB ::
(/): updates//x86_64/primary_db | 7.4 MB ::
bintray--sbt-rpm /
Package device-mapper-persistent-data-0.7.-.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package lvm2.x86_64 :2.02.-.el7 will be updated
---> Package lvm2.x86_64 :2.02.-.el7_6. will be an update
--> Processing Dependency: lvm2-libs = :2.02.-.el7_6. for package: :lvm2-2.02.-.el7_6..x86_64
---> Package yum-utils.noarch :1.1.-.el7 will be installed
--> Processing Dependency: python-kitchen for package: yum-utils-1.1.-.el7.noarch
--> Processing Dependency: libxml2-python for package: yum-utils-1.1.-.el7.noarch
--> Running transaction check
---> Package libxml2-python.x86_64 :2.9.-.el7_2. will be installed
---> Package lvm2-libs.x86_64 :2.02.-.el7 will be updated
---> Package lvm2-libs.x86_64 :2.02.-.el7_6. will be an update
--> Processing Dependency: device-mapper-event = :1.02.-.el7_6. for package: :lvm2-libs-2.02.-.el7_6..x86_64
---> Package python-kitchen.noarch :1.1.-.el7 will be installed
--> Processing Dependency: python-chardet for package: python-kitchen-1.1.-.el7.noarch
--> Running transaction check
---> Package device-mapper-event.x86_64 :1.02.-.el7 will be updated
---> Package device-mapper-event.x86_64 :1.02.-.el7_6. will be an update
--> Processing Dependency: device-mapper-event-libs = :1.02.-.el7_6. for package: :device-mapper-event-1.02.-.el7_6..x86_64
--> Processing Dependency: device-mapper = :1.02.-.el7_6. for package: :device-mapper-event-1.02.-.el7_6..x86_64
---> Package python-chardet.noarch :2.2.-.el7_1 will be installed
--> Running transaction check
---> Package device-mapper.x86_64 :1.02.-.el7 will be updated
--> Processing Dependency: device-mapper = :1.02.-.el7 for package: :device-mapper-libs-1.02.-.el7.x86_64
---> Package device-mapper.x86_64 :1.02.-.el7_6. will be an update
---> Package device-mapper-event-libs.x86_64 :1.02.-.el7 will be updated
---> Package device-mapper-event-libs.x86_64 :1.02.-.el7_6. will be an update
--> Running transaction check
---> Package device-mapper-libs.x86_64 :1.02.-.el7 will be updated
---> Package device-mapper-libs.x86_64 :1.02.-.el7_6. will be an update
--> Finished Dependency Resolution Dependencies Resolved ========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
yum-utils noarch 1.1.-.el7 base k
Updating:
lvm2 x86_64 :2.02.-.el7_6. updates 1.3 M
Installing for dependencies:
libxml2-python x86_64 2.9.-.el7_2. base k
python-chardet noarch 2.2.-.el7_1 base k
python-kitchen noarch 1.1.-.el7 base k
Updating for dependencies:
device-mapper x86_64 :1.02.-.el7_6. updates k
device-mapper-event x86_64 :1.02.-.el7_6. updates k
device-mapper-event-libs x86_64 :1.02.-.el7_6. updates k
device-mapper-libs x86_64 :1.02.-.el7_6. updates k
lvm2-libs x86_64 :2.02.-.el7_6. updates 1.1 M Transaction Summary
========================================================================================
Install Package (+ Dependent packages)
Upgrade Package (+ Dependent packages) Total download size: 4.2 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(/): device-mapper-1.02.-.el7_6..x86_64.rpm | kB ::
(/): libxml2-python-2.9.-.el7_2..x86_64.rpm | kB ::
(/): device-mapper-event-libs-1.02.-.el7_6..x86_64.rpm | kB ::
(/): device-mapper-event-1.02.-.el7_6..x86_64.rpm | kB ::
(/): python-chardet-2.2.-.el7_1.noarch.rpm | kB ::
(/): device-mapper-libs-1.02.-.el7_6..x86_64.rpm | kB ::
(/): yum-utils-1.1.-.el7.noarch.rpm | kB ::
(/): lvm2-libs-2.02.-.el7_6..x86_64.rpm | 1.1 MB ::
(/): python-kitchen-1.1.-.el7.noarch.rpm | kB ::
(/): lvm2-2.02.-.el7_6..x86_64.rpm | 1.3 MB ::
---------------------------------------------------------------------------------------
Total kB/s | 4.2 MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : :device-mapper-1.02.-.el7_6..x86_64 /
Updating : :device-mapper-libs-1.02.-.el7_6..x86_64 /
Updating : :device-mapper-event-libs-1.02.-.el7_6..x86_64 /
Updating : :device-mapper-event-1.02.-.el7_6..x86_64 /
Updating : :lvm2-libs-2.02.-.el7_6..x86_64 /
Installing : python-chardet-2.2.-.el7_1.noarch /
Installing : python-kitchen-1.1.-.el7.noarch /
Installing : libxml2-python-2.9.-.el7_2..x86_64 /
Installing : yum-utils-1.1.-.el7.noarch /
Updating : :lvm2-2.02.-.el7_6..x86_64 /
Cleanup : :lvm2-2.02.-.el7.x86_64 /
Cleanup : :lvm2-libs-2.02.-.el7.x86_64 /
Cleanup : :device-mapper-event-1.02.-.el7.x86_64 /
Cleanup : :device-mapper-event-libs-1.02.-.el7.x86_64 /
Cleanup : :device-mapper-1.02.-.el7.x86_64 /
Cleanup : :device-mapper-libs-1.02.-.el7.x86_64 /
Verifying : :device-mapper-event-1.02.-.el7_6..x86_64 /
Verifying : :device-mapper-libs-1.02.-.el7_6..x86_64 /
Verifying : yum-utils-1.1.-.el7.noarch /
Verifying : libxml2-python-2.9.-.el7_2..x86_64 /
Verifying : python-chardet-2.2.-.el7_1.noarch /
Verifying : :device-mapper-event-libs-1.02.-.el7_6..x86_64 /
Verifying : python-kitchen-1.1.-.el7.noarch /
Verifying : :lvm2-2.02.-.el7_6..x86_64 /
Verifying : :lvm2-libs-2.02.-.el7_6..x86_64 /
Verifying : :device-mapper-1.02.-.el7_6..x86_64 /
Verifying : :device-mapper-event-libs-1.02.-.el7.x86_64 /
Verifying : :device-mapper-1.02.-.el7.x86_64 /
Verifying : :device-mapper-event-1.02.-.el7.x86_64 /
Verifying : :lvm2-libs-2.02.-.el7.x86_64 /
Verifying : :lvm2-2.02.-.el7.x86_64 /
Verifying : :device-mapper-libs-1.02.-.el7.x86_64 / Installed:
yum-utils.noarch :1.1.-.el7
Dependency Installed:
libxml2-python.x86_64 :2.9.-.el7_2. python-chardet.noarch :2.2.-.el7_1 python-kitchen.noarch :1.1.-.el7
Updated:
lvm2.x86_64 :2.02.-.el7_6.
Dependency Updated:
device-mapper.x86_64 :1.02.-.el7_6. device-mapper-event.x86_64 :1.02.-.el7_6. device-mapper-event-libs.x86_64 :1.02.-.el7_6. device-mapper-libs.x86_64 :1.02.-.el7_6.
lvm2-libs.x86_64 :2.02.-.el7_6.
Complete!
3.2)设置稳定的库
$ sudo yum-config-manager \
--add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #国内阿里库
或者
$ sudo yum-config-manager \
--add-repo https://download.docker.com/linux/centos/docker-ce.repo #官网库
备注:
实际上如果安装了该源,不把其他源移走依然会检测到其他源,此时可以将其他源暂时存放到/etc/yum.repos.d/back下:
$ cd /etc/yum.repos.d/
$ mkdir -p /etc/yum.repos.d/back
$ mv *.repo ./back
$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
执行示例:
[root@master devops]# 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
[root@master devops]# cd /etc/yum.repos.d/
[root@master yum.repos.d]# ls
bintray-sbt-rpm.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo docker-ce.repo mysql-community-source.repo
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo mysql-community.repo
[root@master yum.repos.d]# more docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/stable
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/stable
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/edge
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/edge
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/edge
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/test
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/test
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/test
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/nightly
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/nightly
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/nightly
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
3.3)启用 docker-ce-edge和docker-ce-test(可选)
如果需要最新版本的Docker CE 请使用以下命令:
$ sudo yum-config-manager --enable docker-ce-edge
如果需要测试版本的Docker CE 请使用以下命令:
$ sudo yum-config-manager --enable docker-ce-test
3.4)更新 yum 缓存
sudo yum makecache fast
执行示例:
root@master yum.repos.d]# sudo yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
base | 3.6 kB ::
bintray--sbt-rpm | 1.3 kB ::
docker-ce-stable | 3.5 kB ::
# 出现这个问题的原因就是因为/etc/yum.repos.d/下其他源没有被移走,避免该方式可以把除了docker-ce.repo外的其他源暂时转移到/etc/yum.repos.d/back下,等安装完后在将back恢复。
http://mirrors.cn99.com/centos/7.5.1804/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
mysql-connectors-community | 2.5 kB ::
mysql-tools-community | 2.5 kB ::
mysql57-community | 2.5 kB ::
updates | 3.4 kB ::
(/): docker-ce-stable/x86_64/primary_db | kB ::
(/): docker-ce-stable/x86_64/updateinfo | B ::
Metadata Cache Created
[root@master yum.repos.d]#
3)查看repo中列出可用版本
$ sudo yum list docker-ce --showduplicates | sort -r
运行示例:
[root@master yum.repos.d]# yum list docker-ce --showduplicates | sort -r
http://mirrors.cn99.com/centos/7.5.1804/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
* updates: mirror.bit.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
* extras: mirror.bit.edu.cn
docker-ce.x86_64 :19.03.-.el7 docker-ce-stable
docker-ce.x86_64 :19.03.-.el7 docker-ce-stable
docker-ce.x86_64 :18.09.-.el7 docker-ce-stable
docker-ce.x86_64 :18.09.-.el7 docker-ce-stable
docker-ce.x86_64 :18.09.-.el7 docker-ce-stable
docker-ce.x86_64 :18.09.-.el7 docker-ce-stable
docker-ce.x86_64 :18.09.-.el7 docker-ce-stable
docker-ce.x86_64 :18.09.-.el7 docker-ce-stable
docker-ce.x86_64 :18.09.-.el7 docker-ce-stable
docker-ce.x86_64 :18.09.-.el7 docker-ce-stable
docker-ce.x86_64 :18.09.-.el7 docker-ce-stable
docker-ce.x86_64 18.06..ce-.el7 docker-ce-stable
docker-ce.x86_64 18.06..ce-.el7 docker-ce-stable
docker-ce.x86_64 18.06..ce-.el7 docker-ce-stable
docker-ce.x86_64 18.06..ce-.el7 docker-ce-stable
docker-ce.x86_64 18.03..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 18.03..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.12..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.12..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.09..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.09..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.06..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.06..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.06..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.03..ce-.el7 docker-ce-stable
docker-ce.x86_64 17.03..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.03..ce-.el7.centos docker-ce-stable
docker-ce.x86_64 17.03..ce-.el7.centos docker-ce-stable
* base: mirrors.huaweicloud.com
Available Packages
[root@master yum.repos.d]#
4)选择版本安装:例如,docker-ce-18.06.0.ce-3.el7
$ sudo yum install docker-ce-<VERSION_STRING>
$ sudo yum -y install docker-ce #默认安装方式是 获取最新的。
[root@master yum.repos.d]# sudo yum install docker-ce-18.06..ce-.el7
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
http://mirrors.cn99.com/centos/7.5.1804/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 :18.09.-.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: :docker-ce-18.09.-.el7.x86_64
--> Processing Dependency: libseccomp >= 2.3 for package: :docker-ce-18.09.-.el7.x86_64
--> Processing Dependency: containerd.io for package: :docker-ce-18.09.-.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: :docker-ce-18.09.-.el7.x86_64
--> Processing Dependency: libcgroup for package: :docker-ce-18.09.-.el7.x86_64
--> Processing Dependency: libseccomp.so.()(64bit) for package: :docker-ce-18.09.-.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch :2.68-.el7 will be installed
--> Processing Dependency: policycoreutils-python for package: :container-selinux-2.68-.el7.noarch
---> Package containerd.io.x86_64 :1.2.-3.3.el7 will be installed
--> Processing Dependency: container-selinux >= :2.74 for package: containerd.io-1.2.-3.3.el7.x86_64
---> Package docker-ce-cli.x86_64 :19.03.-.el7 will be installed
---> Package libcgroup.x86_64 :0.41-.el7 will be installed
---> Package libseccomp.x86_64 :2.3.-.el7 will be installed
--> Running transaction check
---> Package containerd.io.x86_64 :1.2.-3.3.el7 will be installed
--> Processing Dependency: container-selinux >= :2.74 for package: containerd.io-1.2.-3.3.el7.x86_64
---> Package policycoreutils-python.x86_64 :2.5-.el7_6. will be installed
--> Processing Dependency: policycoreutils = 2.5-.el7_6. for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: setools-libs >= 3.3.- for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: libsemanage-python >= 2.5- for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: audit-libs-python >= 2.1.- for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: libqpol.so.(VERS_1.)(64bit) for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: libqpol.so.(VERS_1.)(64bit) for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: libapol.so.(VERS_4.)(64bit) for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: libqpol.so.()(64bit) for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Processing Dependency: libapol.so.()(64bit) for package: policycoreutils-python-2.5-.el7_6..x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 :2.8.-.el7 will be installed
--> Processing Dependency: audit-libs(x86-) = 2.8.-.el7 for package: audit-libs-python-2.8.-.el7.x86_64
---> Package checkpolicy.x86_64 :2.5-.el7 will be installed
---> Package containerd.io.x86_64 :1.2.-3.3.el7 will be installed
--> Processing Dependency: container-selinux >= :2.74 for package: containerd.io-1.2.-3.3.el7.x86_64
---> Package libsemanage-python.x86_64 :2.5-.el7 will be installed
--> Processing Dependency: libsemanage = 2.5-.el7 for package: libsemanage-python-2.5-.el7.x86_64
---> Package policycoreutils.x86_64 :2.5-.el7 will be updated
---> Package policycoreutils.x86_64 :2.5-.el7_6. will be an update
--> Processing Dependency: libsepol >= 2.5- for package: policycoreutils-2.5-.el7_6..x86_64
--> Processing Dependency: libselinux-utils >= 2.5- for package: policycoreutils-2.5-.el7_6..x86_64
---> Package python-IPy.noarch :0.75-.el7 will be installed
---> Package setools-libs.x86_64 :3.3.-.el7 will be installed
--> Processing Dependency: libselinux >= 2.5-14.1 for package: setools-libs-3.3.-.el7.x86_64
--> Running transaction check
---> Package audit-libs.x86_64 :2.8.-.el7 will be updated
--> Processing Dependency: audit-libs(x86-) = 2.8.-.el7 for package: audit-2.8.-.el7.x86_64
---> Package audit-libs.x86_64 :2.8.-.el7 will be an update
---> Package containerd.io.x86_64 :1.2.-3.3.el7 will be installed
--> Processing Dependency: container-selinux >= :2.74 for package: containerd.io-1.2.-3.3.el7.x86_64
---> Package libselinux.x86_64 :2.5-.el7 will be updated
--> Processing Dependency: libselinux(x86-) = 2.5-.el7 for package: libselinux-python-2.5-.el7.x86_64
---> Package libselinux.x86_64 :2.5-14.1.el7 will be an update
---> Package libselinux-utils.x86_64 :2.5-.el7 will be updated
---> Package libselinux-utils.x86_64 :2.5-14.1.el7 will be an update
---> Package libsemanage.x86_64 :2.5-.el7 will be updated
---> Package libsemanage.x86_64 :2.5-.el7 will be an update
---> Package libsepol.x86_64 :2.5-8.1.el7 will be updated
---> Package libsepol.x86_64 :2.5-.el7 will be an update
--> Running transaction check
---> Package audit.x86_64 :2.8.-.el7 will be updated
---> Package audit.x86_64 :2.8.-.el7 will be an update
---> Package containerd.io.x86_64 :1.2.-3.3.el7 will be installed
--> Processing Dependency: container-selinux >= :2.74 for package: containerd.io-1.2.-3.3.el7.x86_64
---> Package libselinux-python.x86_64 :2.5-.el7 will be updated
---> Package libselinux-python.x86_64 :2.5-14.1.el7 will be an update
--> Finished Dependency Resolution
Error: Package: containerd.io-1.2.6-3.3.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2:2.74
Available: 2:container-selinux-2.42-1.gitad8f0f7.el7.noarch (extras)
container-selinux = 2:2.42-1.gitad8f0f7.el7
Available: 2:container-selinux-2.55-1.el7.noarch (extras)
container-selinux = 2:2.55-1.el7
Available: 2:container-selinux-2.66-1.el7.noarch (extras)
container-selinux = 2:2.66-1.el7
Installing: 2:container-selinux-2.68-1.el7.noarch (extras)
container-selinux = 2:2.68-1.el7
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
[root@master yum.repos.d]#
错误解决方案:
1、下载container-selinux:
$ sudo wget http://mirrors.atosworldline.com/public/centos/7/extras/x86_64/Packages/container-selinux-2.68-1.el7.noarch.rpm
执行示例:
[root@master devops]# wget http://mirrors.atosworldline.com/public/centos/7/extras/x86_64/Packages/container-selinux-2.68-1.el7.noarch.rpm
---- ::-- http://mirrors.atosworldline.com/public/centos/7/extras/x86_64/Packages/container-selinux-2.68-1.el7.noarch.rpm
Resolving mirrors.atosworldline.com (mirrors.atosworldline.com)... 160.92.141.107
Connecting to mirrors.atosworldline.com (mirrors.atosworldline.com)|160.92.141.107|:... connected.
HTTP request sent, awaiting response... OK
Length: (36K) [application/x-redhat-package-manager]
Saving to: ‘container-selinux-2.68-.el7.noarch.rpm’ %[======================================>] , .4KB/s in .6s -- :: (59.4 KB/s) - ‘container-selinux-2.68-.el7.noarch.rpm’ saved [/]
2、安装container-selinux(使用–nodeps --force跳过依赖检查):
rpm -ivh container-selinux-2.68-.el7.noarch.rpm --nodeps --force
简单来说缺少container-selinux包,直接yum install container-selinux -y 完美解决;
执行示例:
[root@master devops]# rpm -ivh container-selinux-2.68-.el7.noarch.rpm --nodeps --force
Preparing... ################################# [%]
Updating / installing...
:container-selinux-:2.68-.el7 ################################# [%]
[root@master devops]#
3、重新安装
sudo yum install docker-ce-18.06..ce-.el7
执行示例:
[root@master devops]# sudo yum install docker-ce-18.06..ce-.el7
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
http://mirrors.cn99.com/centos/7.5.1804/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 :18.06..ce-.el7 will be installed
--> Processing Dependency: libseccomp >= 2.3 for package: docker-ce-18.06..ce-.el7.x86_64
--> Processing Dependency: libcgroup for package: docker-ce-18.06..ce-.el7.x86_64
--> Processing Dependency: libseccomp.so.()(64bit) for package: docker-ce-18.06..ce-.el7.x86_64
--> Running transaction check
---> Package libcgroup.x86_64 :0.41-.el7 will be installed
---> Package libseccomp.x86_64 :2.3.-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ===========================================================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================================================
Installing:
docker-ce x86_64 18.06..ce-.el7 docker-ce-stable M
Installing for dependencies:
libcgroup x86_64 0.41-.el7 base k
libseccomp x86_64 2.3.-.el7 base k Transaction Summary
===========================================================================================================================================================================================================
Install Package (+ Dependent packages) Total download size: M
Installed size: M
Is this ok [y/d/N]: y
Downloading packages:
(/): libseccomp-2.3.-.el7.x86_64.rpm | kB ::
(/): libcgroup-0.41-.el7.x86_64.rpm | kB ::
warning: /var/cache/yum/x86_64//docker-ce-stable/packages/docker-ce-18.06..ce-.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY================-] kB/s | MB :: ETA
Public key for docker-ce-18.06..ce-.el7.x86_64.rpm is not installed
(/): docker-ce-18.06..ce-.el7.x86_64.rpm | MB ::
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.1 MB/s | MB ::
Retrieving key from https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <docker@docker.com>"
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : libcgroup-0.41-.el7.x86_64 /
Installing : libseccomp-2.3.-.el7.x86_64 /
Installing : docker-ce-18.06..ce-.el7.x86_64 /
Verifying : libseccomp-2.3.-.el7.x86_64 /
Verifying : libcgroup-0.41-.el7.x86_64 /
Verifying : docker-ce-18.06..ce-.el7.x86_64 / Installed:
docker-ce.x86_64 :18.06..ce-.el7 Dependency Installed:
libcgroup.x86_64 :0.41-.el7 libseccomp.x86_64 :2.3.-.el7 Complete!
[root@master devops]#
5)启动 Docker 并加入开机启动
$ sudo systemctl start docker
$ sudo systemctl enable docker
[root@master devops]# sudo systemctl start docker
[root@master devops]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Thu -- :: CST; 8s ago
Docs: https://docs.docker.com
Main PID: (dockerd)
Tasks:
Memory: 48.5M
CGroup: /system.slice/docker.service
├─ /usr/bin/dockerd
└─ docker-containerd --config /var/run/docker/containerd/containerd.toml Aug :: master dockerd[]: time="2019-08-22T22:46:21.480103757+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Aug :: master dockerd[]: time="2019-08-22T22:46:21.480130688+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc42033df20, CONNECTING" module=grpc
Aug :: master dockerd[]: time="2019-08-22T22:46:21.480250962+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc42033df20, READY" module=grpc
Aug :: master dockerd[]: time="2019-08-22T22:46:21.480265755+08:00" level=info msg="Loading containers: start."
Aug :: master dockerd[]: time="2019-08-22T22:46:21.720656638+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
Aug :: master dockerd[]: time="2019-08-22T22:46:21.798473819+08:00" level=info msg="Loading containers: done."
Aug :: master dockerd[]: time="2019-08-22T22:46:21.812271357+08:00" level=info msg="Docker daemon" commit=0ffa825 graphdriver(s)=overlay2 version=18.06.-ce
Aug :: master dockerd[]: time="2019-08-22T22:46:21.812437469+08:00" level=info msg="Daemon has completed initialization"
Aug :: master dockerd[]: time="2019-08-22T22:46:21.846494024+08:00" level=info msg="API listen on /var/run/docker.sock"
Aug :: master systemd[]: Started Docker Application Container Engine.
[root@master devops]#
[root@master devops]# sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@master devops]#
6)建立docker用户组
默认情况下,docker命令会使用 Unix socket 与Docker引擎通讯。而只有root用户和docker组的用户才可以访问docker引擎的Unix socket。出于安全考虑,一般Unix系统上不会直接使用root用户。因此,更好的做法是将需要使用docker的用户加入docke用户组。
建立docker用户组:
$ sudo groupadd docker
将当前用户加入docker组:
$ sudo usermode -aG docker $USER
退出当前终端并重新登录。
7)验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
$ yum list installed | grep docker #查看已经安装的docker组件
$ sudo docker version #查看Docker版本信息
$ sudo docker info #查看Docker信息
查看已经安装的docker组件
[root@master docker]# yum list installed | grep docker
docker-ce.x86_64 18.06..ce-.el7 @docker-ce-stable
查看Docker版本信息
[root@master devops]# docker version
Client:
Version: 18.06.-ce
API version: 1.38
Go version: go1.10.3
Git commit: 0ffa825
Built: Wed Jul ::
OS/Arch: linux/amd64
Experimental: false Server:
Engine:
Version: 18.06.-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: 0ffa825
Built: Wed Jul ::
OS/Arch: linux/amd64
Experimental: false
[root@master devops]#
查看Docker信息
[root@master docker]# sudo docker info
Containers:
Running:
Paused:
Stopped:
Images:
Server Version: 18.06.-ce
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: d64c661f1d51c48782c9cec8fda7604785f93587
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.-.el7.x86_64
Operating System: CentOS Linux (Core)
OSType: linux
Architecture: x86_64
CPUs:
Total Memory: .671GiB
Name: master
ID: QIKO:U734:PE2L:PTJE:7NXC:ATTJ:HB3Z:3KLL:KXA6:QQKJ:OIW5:FJA2
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/
Live Restore Enabled: false WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
8)测试运行 hello-world
$ docker run hello-world
执行示例:
[root@master devops]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:451ce787d12369c5df2a32c85e5a03d52cbcef6eb3586dd03075f3034f10adcd
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:
. The Docker client contacted the Docker daemon.
. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
. 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@master devops]#
由于本地没有hello-world这个镜像,所以会下载一个hello-world的镜像,并在容器内运行。
9)镜像加速
鉴于国内网络问题,拉取 Docker 镜像比较缓慢,我们可以通过配置加速器来解决,我使用的是网易的镜像地址:http://hub-mirror.c.163.com。
新版的 Docker 使用/etc/docker/daemon.json(Linux,没有该文件的话,请先建一个),%programdata%\docker\config\daemon.json(Windows)来配置 Daemon。
请在/etc/docker/daemon.json(Linux,没有该文件的话,请先建一个)配置文件中加入:
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
注意,一定要保证该文件符合 json 规范,否则 Docker 将不能启动。
之后重新启动服务。
[root@localhost ~]# sudo systemctl daemon-reload
[root@localhost ~]# sudo systemctl restart docker
备注:
docker-cn镜像:
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
腾讯云
{
"registry-mirrors": ["https://mirror.ccs.tencentyun.com"]
}
阿里云
https://yq.aliyun.com/articles/29941
也可参考:《centos7:docker使用阿里云镜像加速器的方法,链接:https://my.oschina.net/u/3707314/blog/1635184》
参考
1)《【深度知识】DOCKER入门,框架原理,镜像制作和资源列表》
Devops(二):CentOS7(在线)安装Docker的更多相关文章
- docker(一) Centos7下安装docker
docker(一) Centos7下安装dockerdocker(二) windows10下安装dockerdocker(三) 镜像和容器常用命令 docker(四) 使用Dockerfile构建镜像 ...
- Centos7上安装docker (转)
Centos7上安装docker Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如 ...
- docker(二) windows10下安装docker
官方安装文档: https://docs.docker.com/docker-for-windows/install/ https://docs.docker.com/docker-for-windo ...
- CentOS7下安装docker(Docker系列1)
CentOS7下安装docker 系统要求 为了安装docker,需要准备 64-bit的CentOS 7 删除非官方的Docker包 yum的仓库中有一个很旧的Docker包, 现在Docker官方 ...
- Centos 7系统在线安装docker
在线安装docker 以下操作步骤均在root用户下操作 1. 检查内核是否符合要求 Docker 要求 Centos系统的内核版本高于 3.10 ,建议在Centos 7版本命令如下: uname ...
- centos7上安装docker社区版
container(容器) docker(集装箱) 容器的优点 1. 启动速度快 2. 节省资源 3. 兼容性高 保证机器正常上网 #ping www.baidu.com CPU需要支持虚拟化 # g ...
- centos7下安装docker与镜像加速
1.背景 centos7下安装docker 2.安装 第一步:检查是否为centos7版本 第二步:依赖环境安装 执行如下两个命令: yum -y install gcc yum -y install ...
- CentOS7用阿里云Docker Yum源在线安装Docker
一.参考文档 官方Docker安装文档:https://docs.docker.com/install/linux/docker-ce/centos 阿里云Docker安装文档:https://yq. ...
- CentOS7用阿里云Docker Yum源在线安装Docker 17.03.2
参考文档 安装步骤 删除已安装的Docker 配置阿里云Docker Yum源 安装指定版本 启动Docker服务 参考文档 官方Docker安装文档:https://docs.docker. ...
- Centos7下安装Docker(详细的新手装逼教程)
早就听说过Docker,一直不清楚是个啥,今天捣鼓了一下,这里做个记录. --------------------------------------------------------------- ...
随机推荐
- k8s维护常用命令
k8s维护 1. 不可调度 kubectl cordon k8s-node-1 kubectl uncordon k8s-node-1 #取消 2.驱逐已经运行的业务容器 kubectl drain ...
- H3C 802.11 MAC层工作原理
- Python,for循环小例子--99乘法表
一.99乘法表 for i in range(1, 10): for j in range(1, i + 1): print('%sx%s=%s ' % (j, i, j * i), end='') ...
- gps示例代码
/* main.c */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #incl ...
- TCN时间卷积网络——解决LSTM的并发问题
TCN是指时间卷积网络,一种新型的可以用来解决时间序列预测的算法.在这一两年中已有多篇论文提出,但是普遍认为下篇论文是TCN的开端. 论文名称: An Empirical Evaluation of ...
- Integer面试连环炮以及源码分析
场景: 昨天有位朋友去面试,我问他面试问了哪些问题,其中问了Integer相关的问题,以下就是面试官问的问题,还有一些是我对此做了扩展. 问:两个new Integer 128相等吗? 答:不.因 ...
- 1、Python简介与Python安装
一.Python简介: Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python的创始人为吉多·范罗苏姆(Guido van Rossum)少数几个不秃头的语言创始 ...
- intellij高亮字体背景颜色
https://blog.csdn.net/aosica321/article/details/52956419 https://blog.csdn.net/lxzpp/article/details ...
- Spark数据倾斜解决方案(转)
本文转发自技术世界,原文链接 http://www.jasongj.com/spark/skew/ Spark性能优化之道——解决Spark数据倾斜(Data Skew)的N种姿势 发表于 2017 ...
- LeetCode 875. Koko Eating Bananas
原题链接在这里:https://leetcode.com/problems/koko-eating-bananas/ 题目: Koko loves to eat bananas. There are ...