背景
最近在研究开源数据库,由于机器存储空间有限。计划把个人的测试环境等迁移到docker上去,方便后续加快完成搭建等工作,把时间用到该用的地方去。
集成环境
个人测试环境,我与IT人无异都是喜欢把部分环境放到虚拟机上。
项目 | 描述 |
---|---|
操作系统 | CentOS Linux release 7.6.1810 x86_64 |
内存 | 2G |
硬盘大小 | 30G |
CPU | Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz |
DOCKER | 18.09.1-3.el7 (stable) |
虚拟机软件 | Oracle VM VirtualBox 6.0.2 |
网络状况
项目 | 连接方式 | 描述 |
---|---|---|
网卡1 | Host-Only | 用于本机连接虚拟机 |
网卡2 | NAT | 用于公共环境下访问外网,如wlan |
网卡3 | Bridge | 用于办公/家庭网络情况下访问外网 |
OS禁用项目列表
- NetworkManager
systemctl stop NetworkManager
systemctl disable NetworkManager
- Firewalld
systemctl stop firewalld
systemctl disable firewalld
- selinux
修改文件/etc/selinux/config
SELINUX=enforcing ---->把值调整为disabled
安装过程、遇到问题及其解决方案
- 更新yum资源库,以便后续安装时可以不会因版本问题导致安装报错。
yum update
- 卸载已安装的docker组件
yum remove docker docker-common docker-selinux docker-engine
- 安装docker所需依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
- 把docker-ce的资源文件下载到本地
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
在执行过程中,有以下报错提示:
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
Could not fetch/save url https://download.docker.com/linux/centos/docker-ce.repo to file /etc/yum.repos.d/docker-ce.repo: [Errno 14] curl#6 - "Could not resolve host: download.docker.com; Unknown error"
由于我安装环境经过N层代理和防火墙,判断为网络问题。直接下载repo文件到本地并在服务器存放目录下执行:
# yum-config-manager --add-repo docker-ce.repo
Loaded plugins: fastestmirror ------->从这开始是执行结果
adding repo from: docker-ce.repo
grabbing file docker-ce.repo to /tmp/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
- 查看docker可安装版本
yum list docker-ce --showduplicates | sort -r
Loading mirror speeds from cached hostfile ------>以下开始是结果
Loaded plugins: fastestmirror
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.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
Available Packages
- 安装docker-ce软件
默认安装最新版本:
yum install docker-ce
如需安装特定版本:
yum install docker-ce-18.09.0
在过程中,以下是报错提示:
# yum install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:18.09.1-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: containerd.io for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.2-3.el7 will be installed
---> Package docker-ce.x86_64 3:18.09.1-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.1-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:18.09.1-3.el7 will be installed
--> Processing Dependency: libltdl.so.7()(64bit) for package: 1:docker-ce-cli-18.09.1-3.el7.x86_64
---> Package libcgroup.x86_64 0:0.41-20.el7 will be installed
--> Running transaction check
---> Package docker-ce.x86_64 3:18.09.1-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.1-3.el7.x86_64
---> Package libtool-ltdl.x86_64 0:2.4.2-22.el7_3 will be installed
--> Finished Dependency Resolution
Error: Package: 3:docker-ce-18.09.1-3.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2.9
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
在yum安装的过程中,发现缺失包container-selinux,而且版本是2.9以上。我翻遍了全网,并没有找到这个包。最后无奈之下,在centos官网下载了一个container-selinux-2.74的RPM包尝试看看。
# yum install container-selinux-2.74-1.el7.noarch.rpm
Loaded plugins: fastestmirror
.......... ------>这里省略了N行信息
Installed:
container-selinux.noarch 2:2.74-1.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.8.4-4.el7 checkpolicy.x86_64 0:2.5-8.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 python-IPy.noarch 0:0.75-6.el7
setools-libs.x86_64 0:3.3.8-4.el7
Complete!
接下来,尝试继续安装docker-ce。
yum install docker-ce
问题解决,但由于网络问题,下载了N久都是在报错。又开启了老办法模式,下载包到本地进行安装。
根据yum资料库的分析
=================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================
Installing:
docker-ce x86_64 3:18.09.1-3.el7 docker-ce-stable 19 M
Installing for dependencies:
containerd.io x86_64 1.2.2-3.el7 docker-ce-stable 22 M
docker-ce-cli x86_64 1:18.09.1-3.el7 docker-ce-stable 14 M
libtool-ltdl x86_64 2.4.2-22.el7_3 Base 49 k
一共需要4个依赖包,其中libtool-ltdl在Base下,即在光盘中,无需下载。其他3个依赖包就需要在docker的网站上进行下载。下载并上传到本地,使用yum命令进行安装:
yum install docker-ce-cli-18.09.1-3.el7.x86_64.rpm
yum install containerd.io-1.2.2-3.el7.x86_64.rpm
yum install docker-ce-18.09.1-3.el7.x86_64.rpm
当显示Complete!时,检查安装版本:
# systemctl start docker
# docker version
Client: ------->以下开始为结果
Version: 18.09.1
API version: 1.39
Go version: go1.10.6
Git commit: 4c52b90
Built: Wed Jan 9 19:35:01 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.1
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 4c52b90
Built: Wed Jan 9 19:06:30 2019
OS/Arch: linux/amd64
Experimental: false
至此,我的心情有多鸡冻呀!之前虽然在ubuntu上安装过,但是无那么多问题。这次真算是好事多磨了。
赶紧设置开机自启动:
systemctl enable docker