1、安装环境
(1)内核版本:uname -a
Linux zxomc 3.10.5-3.el6.x86_64 #1 SMP Tue Aug 20 14:10:49 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
(2) lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.10 (Final)
Release: 6.10
Codename: Final
(3)离线环境,在线环境下没有这么复杂
2、安装的简易步骤
(1)以超级用户进入到/etc/yum.repos.d/
(2)从网上下载要安装的epel-release-6-8.noarch.rpm包,并移到此目录下
epel-release-6-8.noarch.rpm包可下载地址:
https://centos.pkgs.org/6/epel-i386/epel-release-6-8.noarch.rpm.html
(3)执行如下命令:yum makecache
已加载插件:fastestmirror, refresh-packagekit, security
Repository epel is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
base | 3.7 kB 00:00
base/other_db | 2.8 MB 00:00
http://download.fedoraproject.org/pub/epel/6/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - "Failed to connect to 2605:bc80:3010:600:dead:beef:cafe:fed9: 网络不可达"
尝试其他镜像。
错误:Cannot retrieve repository metadata (repomd.xml) for repository: epel. Please verify its path and try again
[root@zxomc yum.repos.d]# ls
bak epel-release-6-8.noarch.rpm epel-testing.repo zte.epel.repo
CentOS-Base.repo.bak epel.repo nohup.out zte-mirrors.repo
[root@zxomc yum.repos.d]# mv epel.repo epel.repo.bak
[root@zxomc yum.repos.d]# mv zte.epel.repo epel.repo
[root@zxomc yum.repos.d]# yum makecache
已加载插件:fastestmirror, refresh-packagekit, security
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
base | 3.7 kB 00:00
epel | 5.3 kB 00:00
epel/group_gz | 71 kB 00:00
epel/filelists_db | 7.9 MB 00:01
epel/updateinfo | 789 kB 00:00
epel/prestodelta | 838 B 00:00
epel/primary_db | 6.1 MB 00:00
epel/other_db | 3.0 MB 00:00
extras | 3.4 kB 00:00
extras/prestodelta | 2.2 kB 00:00
extras/other_db | 14 kB 00:00
zabbix | 951 B 00:00
zabbix/other | 3.1 kB 00:00
zabbix 29/29
元数据缓存已建立
(4)然后执行如下命令:rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
package epel-release-6-8.noarch is already installed
[root@zxomc yum.repos.d]# yum search docker-io
已加载插件:fastestmirror, refresh-packagekit, security
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
警告:没有匹配 docker-io 的软件包
没有找到匹配的软件包
[root@zxomc yum.repos.d]# yum install docker-io
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
No package docker-io available.
错误:无须任何处理
[root@zxomc yum.repos.d]# yum install docker
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
解决依赖关系
--> 执行事务检查
---> Package docker.x86_64 0:1.5-5.el6 will be 安装
--> 完成依赖关系计算
依赖关系解决
=============================================================================================================
软件包 架构 版本 仓库 大小
=============================================================================================================
正在安装:
docker x86_64 1.5-5.el6 epel 19 k
事务概要
=============================================================================================================
Install 1 Package(s)
总下载量:19 k
Installed size: 37 k
确定吗?[y/N]:y
下载软件包:
docker-1.5-5.el6.x86_64.rpm | 19 kB 00:00
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
Userid : EPEL (6)
Package: epel-release-6-8.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
确定吗?[y/N]:y
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
Warning: RPMDB altered outside of yum.
正在安装 : docker-1.5-5.el6.x86_64 1/1
Verifying : docker-1.5-5.el6.x86_64 1/1
已安装:
docker.x86_64 0:1.5-5.el6
完毕!
(5)yum install docker-engine-1.7.1-1.el6.x86_64.rpm
此文件包的下载地址:
https://www.oschina.net/news/64267/docker-1-7-1-final
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
诊断 docker-engine-1.7.1-1.el6.x86_64.rpm: docker-engine-1.7.1-1.el6.x86_64
docker-engine-1.7.1-1.el6.x86_64.rpm 将被安装
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
解决依赖关系
--> 执行事务检查
---> Package docker-engine.x86_64 0:1.7.1-1.el6 will be 安装
--> 处理依赖关系 libcgroup,它被软件包 docker-engine-1.7.1-1.el6.x86_64 需要
--> 执行事务检查
---> Package libcgroup.x86_64 0:0.40.rc1-26.el6 will be 安装
--> 处理 docker-engine-1.7.1-1.el6.x86_64 与 docker 的冲突
No package matched to upgrade: docker-engine
--> 完成依赖关系计算
错误:docker-engine conflicts with docker-1.5-5.el6.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
此时由于前面安装过程不对,会出现一个错误;主要原因就是步骤(2)安装的rpm包信息不完整,部分依赖关系未包含;
解决此问题方法时将之前安装的docker文件全部清除掉,然后重新执行:yum install docker-engine-1.7.1-1.el6.x86_64.rpm
(6)清除之前安装的docker相关文件的命令
yum remove docker
已加载插件:fastestmirror, refresh-packagekit, security
设置移除进程
解决依赖关系
--> 执行事务检查
---> Package docker.x86_64 0:1.5-5.el6 will be 删除
--> 完成依赖关系计算
依赖关系解决
=============================================================================================================
软件包 架构 版本 仓库 大小
=============================================================================================================
正在删除:
docker x86_64 1.5-5.el6 @epel 37 k
事务概要
=============================================================================================================
Remove 1 Package(s)
Installed size: 37 k
确定吗?[y/N]:y
下载软件包:
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
Repository epel is listed more than once in the configuration
正在删除 : docker-1.5-5.el6.x86_64 1/1
Verifying : docker-1.5-5.el6.x86_64 1/1
删除:
docker.x86_64 0:1.5-5.el6
完毕!
(7)重新执行 yum install docker-engine-1.7.1-1.el6.x86_64.rpm
[root@zxomc ~]# yum install docker-engine-1.7.1-1.el6.x86_64.rpm
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
诊断 docker-engine-1.7.1-1.el6.x86_64.rpm: docker-engine-1.7.1-1.el6.x86_64
docker-engine-1.7.1-1.el6.x86_64.rpm 将被安装
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
解决依赖关系
--> 执行事务检查
---> Package docker-engine.x86_64 0:1.7.1-1.el6 will be 安装
--> 处理依赖关系 libcgroup,它被软件包 docker-engine-1.7.1-1.el6.x86_64 需要
--> 执行事务检查
---> Package libcgroup.x86_64 0:0.40.rc1-26.el6 will be 安装
--> 完成依赖关系计算
依赖关系解决
=============================================================================================================
软件包 架构 版本 仓库 大小
=============================================================================================================
正在安装:
docker-engine x86_64 1.7.1-1.el6 /docker-engine-1.7.1-1.el6.x86_64 19 M
为依赖而安装:
libcgroup x86_64 0.40.rc1-26.el6 base 131 k
事务概要
=============================================================================================================
Install 2 Package(s)
总文件大小:19 M
总下载量:131 k
Installed size: 20 M
确定吗?[y/N]:y
下载软件包:
libcgroup-0.40.rc1-26.el6.x86_64.rpm | 131 kB 00:00
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在安装 : libcgroup-0.40.rc1-26.el6.x86_64 1/2
/sbin/ldconfig: /lib/libuuid.so.1 不是符号连接
/sbin/ldconfig: /lib/libext2fs.so.2 不是符号连接
/sbin/ldconfig: /lib/libattr.so.1 不是符号连接
/sbin/ldconfig: /lib/libpamc.so.0 不是符号连接
/sbin/ldconfig: /lib/libvolume_id.so.0 不是符号连接
/sbin/ldconfig: /lib/libaudit.so.0 不是符号连接
/sbin/ldconfig: /lib/libacl.so.1 不是符号连接
/sbin/ldconfig: /lib/libdbus-1.so.3 不是符号连接
/sbin/ldconfig: /lib/libgmodule-2.0.so.0 不是符号连接
/sbin/ldconfig: /lib/libasound.so.2 不是符号连接
/sbin/ldconfig: /lib/libtermcap.so.2 不是符号连接
/sbin/ldconfig: /lib/libauparse.so.0 不是符号连接
/sbin/ldconfig: /lib/libblkid.so.1 不是符号连接
/sbin/ldconfig: /lib/libgobject-2.0.so.0 不是符号连接
/sbin/ldconfig: /lib/libpam_misc.so.0 不是符号连接
/sbin/ldconfig: /lib/libe2p.so.2 不是符号连接
/sbin/ldconfig: /lib/libpam.so.0 不是符号连接
/sbin/ldconfig: /lib/libss.so.2 不是符号连接
/sbin/ldconfig: /lib/libexpat.so.0 不是符号连接
/sbin/ldconfig: /lib/libcom_err.so.2 不是符号连接
/sbin/ldconfig: /lib/libgthread-2.0.so.0 不是符号连接
/sbin/ldconfig: /lib/libwrap.so.0 不是符号连接
/sbin/ldconfig: /lib/libcap.so.1 不是符号连接
/sbin/ldconfig: /lib/libglib-2.0.so.0 不是符号连接
正在安装 : docker-engine-1.7.1-1.el6.x86_64 2/2
Verifying : libcgroup-0.40.rc1-26.el6.x86_64 1/2
Verifying : docker-engine-1.7.1-1.el6.x86_64 2/2
已安装:
docker-engine.x86_64 0:1.7.1-1.el6
作为依赖被安装:
libcgroup.x86_64 0:0.40.rc1-26.el6
完毕!
执行到这里,docker基本上安装完毕,可以使用docker的简单命令查看其版本信息,如:
docker --version
Docker version 1.7.1, build 786b29d
使用 docker -h可以看具体支持的命令详细信息如下:
docker -h
Usage: docker [OPTIONS] COMMAND [arg...]
A self-sufficient runtime for linux containers.
Options:
--api-cors-header= Set CORS headers in the remote API
-b, --bridge= Attach containers to a network bridge
--bip= Specify network bridge IP
-D, --debug=false Enable debug mode
-d, --daemon=false Enable daemon mode
--default-gateway= Container default gateway IPv4 address
--default-gateway-v6= Container default gateway IPv6 address
--default-ulimit=[] Set default ulimits for containers
--dns=[] DNS server to use
--dns-search=[] DNS search domains to use
-e, --exec-driver=native Exec driver to use
--exec-opt=[] Set exec driver options
--exec-root=/var/run/docker Root of the Docker execdriver
--fixed-cidr= IPv4 subnet for fixed IPs
--fixed-cidr-v6= IPv6 subnet for fixed IPs
-G, --group=docker Group for the unix socket
-g, --graph=/var/lib/docker Root of the Docker runtime
-H, --host=[] Daemon socket(s) to connect to
-h, --help=false Print usage
--icc=true Enable inter-container communication
--insecure-registry=[] Enable insecure registry communication
--ip=0.0.0.0 Default IP when binding container ports
--ip-forward=true Enable net.ipv4.ip_forward
--ip-masq=true Enable IP masquerading
--iptables=true Enable addition of iptables rules
--ipv6=false Enable IPv6 networking
-l, --log-level=info Set the logging level
--label=[] Set key=value labels to the daemon
--log-driver=json-file Default driver for container logs
--log-opt=map[] Set log driver options
--mtu=0 Set the containers network MTU
-p, --pidfile=/var/run/docker.pid Path to use for daemon PID file
--registry-mirror=[] Preferred Docker registry mirror
-s, --storage-driver= Storage driver to use
--selinux-enabled=false Enable selinux support
--storage-opt=[] Set storage driver options
--tls=false Use TLS; implied by --tlsverify
--tlscacert=~/.docker/ca.pem Trust certs signed only by this CA
--tlscert=~/.docker/cert.pem Path to TLS certificate file
--tlskey=~/.docker/key.pem Path to TLS key file
--tlsverify=false Use TLS and verify the remote
--userland-proxy=true Use userland proxy for loopback traffic
-v, --version=false Print version information and quit
Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders from a container's filesystem to the host path
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Stream the contents of a container as a tar archive
history Show the history of an image
images List images
import Create a new filesystem image from the contents of a tarball
info Display system-wide information
inspect Return low-level information on a container or image
kill Kill a running container
load Load an image from a tar archive
login Register or log in to a Docker registry server
logout Log out from a Docker registry server
logs Fetch the logs of a container
pause Pause all processes within a container
port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
ps List containers
pull Pull an image or a repository from a Docker registry server
push Push an image or a repository to a Docker registry server
rename Rename an existing container
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save an image to a tar archive
search Search for an image on the Docker Hub
start Start a stopped container
stats Display a stream of a containers' resource usage statistics
stop Stop a running container
tag Tag an image into a repository
top Lookup the running processes of a container
unpause Unpause a paused container
version Show the Docker version information
wait Block until a container stops, then print its exit code
Run 'docker COMMAND --help' for more information on a command.
但是这里在试图启动docker服务时,仍然会遇到如下问题:
# service docker start
Starting cgconfig service: Error: cannot mount cpu to /cgroup/cpu: Device or resource busy
/sbin/cgconfigparser; error loading /etc/cgconfig.conf: Cgroup mounting failed
Failed to parse /etc/cgconfig.conf or /etc/cgconfig.d [失败]
Starting docker: [确定]
(8)解决上述问题,可以详细参考如下链接中的文档:https://blog.csdn.net/medwin1986/article/details/41078903
在RedHat/CentOS环境中运行docker、lxc,需要手动重新挂载cgroup;我们首选禁用cgroup对应服务cgconfig。
手动挂载cgroup的步骤:
A)service cgconfig stop:关闭服务
Stopping cgconfig service: cgclear failed with Device or resource busy
[确定]
B)chkconfig cgconfig off:取消开机启动
C)然后挂载cgroup,可以命令行挂载
mount -t cgroup none /cgroup #挂载单次
vim /etc/fstab,none /cgroup cgroup defaults 0 0 #开机挂载
D)启动docker服务
sudo service docker start # 启动服务
这里我遇到了一个cgconfig启动失败的日志:
Starting cgconfig service: Error: cannot mount cpuset to /cgroup/cpuset: Device or resource busy
/sbin/cgconfigparser; error loading /etc/cgconfig.conf: Cgroup mounting failed
Failed to parse /etc/cgconfig.conf or /etc/cgconfig.d[FAILED]
解决方法:cgclear
sudo chkconfig docker on # 开机启动
E)设置为开机启动的方式
vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Jul 2 17:53:39 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_zxomc-lv_root / ext4 defaults 1 1
UUID=17165519-a4c4-4b57-adc3-35b948311595 /boot ext4 defaults 1 2
/dev/mapper/vg_zxomc-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
在这个文件的下面加入 如下的命令:
#
# /etc/fstab
# Created by anaconda on Tue Jul 2 17:53:39 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_zxomc-lv_root / ext4 defaults 1 1
UUID=17165519-a4c4-4b57-adc3-35b948311595 /boot ext4 defaults 1 2
/dev/mapper/vg_zxomc-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
none /cgroup cgroup defaults 0 0
然后重新启动,验证即可(service docker start)。
3、安装docker的相关参考文件及文档
(1)https://www.oschina.net/news/64267/docker-1-7-1-final
(2)pkgs.org
https://pkgs.org/
https://centos.pkgs.org/6/epel-i386/epel-release-6-8.noarch.rpm.html
(3)清华大学开源软件镜像站
https://mirrors.tuna.tsinghua.edu.cn/epel/6/x86_64/Packages/d/
(4)安装时部分问题解决参考文档
https://blog.csdn.net/medwin1986/article/details/41078903
注:上述所有描述为个人安装时的操作,不代表适用于其他环境下docker的安装,但仍然可以作为部分参考使用。