Docker01-安装部署Docker

1 案例1:安装Docker
1.1 问题

本案例要求配置yum源并安装Docker:
准备两台虚拟机,IP为192.168.1.10和192.168.1.20
安装docker-engine 和 docker-engine-selinux
关闭防火墙
1.2 步骤

实现此案例需要按照如下步骤进行。
步骤一:配置yum源

1)配置第三方yum源(真机操作)
[[email protected] ~]# mkdir /var/ftp/docker
[[email protected] ~]# mv docker-engine-* /var/ftp/docker
[[email protected] ~]# ls /var/ftp/docker
docker-engine-1.12.1-1.el7.centos.x86_64.rpm
docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm
[[email protected] ~]# createrepo /var/ftp/docker/
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 1 pkgs
Spawning worker 2 with 0 pkgs
Spawning worker 3 with 0 pkgs
Spawning worker 4 with 0 pkgs
Spawning worker 5 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
2)配置IP(虚拟机配置静态ip)docker1和docker2主机同样操作
[[email protected] ~]# echo docker1 > /etc/hostname
[[email protected] ~]# hostname docker1
[[email protected] ~]# echo docker2 > /etc/hostname
[[email protected] ~]# hostname docker2
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE=”eth0″
ONBOOT=”yes”
IPV6INIT=”no”
IPV4_FAILURE_FATAL=”no”
NM_CONTROLLED=”no”
TYPE=”Ethernet”
BOOTPROTO=”static”
IPADDR=”192.168.1.10″
PREFIX=24
GATEWAY=192.168.1.254
[[email protected] ~]# systemctl restart network
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE=”eth0″
ONBOOT=”yes”
IPV6INIT=”no”
IPV4_FAILURE_FATAL=”no”
NM_CONTROLLED=”no”
TYPE=”Ethernet”
BOOTPROTO=”static”
IPADDR=”192.168.1.20″
PREFIX=24
GATEWAY=192.168.1.254
[[email protected] ~]# systemctl restart network
3)配置yum客户端(docker1和docker2主机同样操作)
[[email protected] ~]# vim /etc/yum.repos.d/local.repo
[local_repo]
name=CentOS-$releasever – Base
baseurl=”ftp://192.168.1.254/system”
enabled=1
gpgcheck=1
[loca]
name=local
baseurl=”ftp://192.168.1.254/docker”
enabled=1
gpgcheck=0

[[email protected] ~]# vim /etc/yum.repos.d/local.repo
[local_repo]
name=CentOS-$releasever – Base
baseurl=”ftp://192.168.1.254/system”
enabled=1
gpgcheck=1
[loca]
name=local
baseurl=”ftp://192.168.1.254/docker”
enabled=1
gpgcheck=0
4)安装docker(docker1和docker2主机同样操作)
[[email protected] ~]# yum -y install docker-engine
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# systemctl enable docker
[[email protected] ~]# ifconfig //有docker0说明环境部署完成
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:3e:e7:3f:6e txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[[email protected] ~]# docker version //查看版本

[[email protected] ~]# yum -y install docker-engine
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# systemctl enable docker
[[email protected] ~]# ifconfig //有docker0说明环境部署完成
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:53:82:b9:d4 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[[email protected] ~]# docker version //查看版本

代码如下
准备好软件包,然后创建个FTP目录,拷贝过去
[[email protected] ~]# mkdir /var/ftp/docker

[[email protected] docker 1]# ll
总用量 271692
-rwxrwxrwx 1 root root 4168 7月 13 01:01 docker_01.txt
-rwxrwxrwx 1 root root 19917380 7月 13 01:01 docker-engine-1.12.1-1.el7.centos.x86_64.rpm
-rwxrwxrwx 1 root root 28860 7月 13 01:01 docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm
-rwxrwxrwx 1 root root 258246973 7月 13 01:02 docker_images.zip

[[email protected] docker 1]# cp docker-engine-* /var/ftp/docker/

[[email protected] docker 1]# ll /var/ftp/docker/
总用量 19484
-rwxr-xr-x 1 root root 19917380 10月 16 10:56 docker-engine-1.12.1-1.el7.centos.x86_64.rpm
-rwxr-xr-x 1 root root 28860 10月 16 10:56 docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm

配置yum源
[[email protected] docker 1]# cd /var/ftp/docker/
[[email protected] docker]# ls
docker-engine-1.12.1-1.el7.centos.x86_64.rpm
docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm
[[email protected] docker]# createrepo /var/ftp/docker/
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 1 pkgs
Spawning worker 2 with 0 pkgs
Spawning worker 3 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[[email protected] docker]# ls
docker-engine-1.12.1-1.el7.centos.x86_64.rpm repodata
docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm

准备2台虚拟机,直接模版克隆就行了,改下IP,主机名,配置YUM源,具体按如下操作
创建2台虚拟机,前端镜像名为docker1.img和docker2.img
[[email protected] images]# qemu-img create -b node.qcow2 -f qcow2 docker1.img
Formatting ‘docker1.img’, fmt=qcow2 size=17179869184 backing_file=’node.qcow2′ encryption=off cluster_size=65536 lazy_refcounts=off
[[email protected] images]# qemu-img info docker1.img
image: docker1.img
file format: qcow2
virtual size: 16G (17179869184 bytes)
disk size: 196K
cluster_size: 65536
backing file: node.qcow2
Format specific information:
compat: 1.1
lazy refcounts: false
[[email protected] images]# qemu-img create -b node.qcow2 -f qcow2 docker2.img
Formatting ‘docker2.img’, fmt=qcow2 size=17179869184 backing_file=’node.qcow2′ encryption=off cluster_size=65536 lazy_refcounts=off
[[email protected] images]# qemu-img info docker2.img
image: docker2.img
file format: qcow2
virtual size: 16G (17179869184 bytes)
disk size: 196K
cluster_size: 65536
backing file: node.qcow2
Format specific information:
compat: 1.1
lazy refcounts: false

编辑xml文件,注意内存稍微给大一点,我都给的4G
[[email protected] images]# cd /etc/libvirt/qemu/
[[email protected] qemu]# sed ‘s/node/docker1/’ /etc/libvirt/qemu/node.xml > /etc/libvirt/qemu/docker1.xml
[[email protected] qemu]# vim docker1.xml
[[email protected] qemu]# sed ‘s/node/docker2/’ /etc/libvirt/qemu/node.xml > /etc/libvirt/qemu/docker2.xml
[[email protected] qemu]# vim docker2.xml

此处就贴1个xml文件,另一个大同小异,名字改一下就行了
[[email protected] qemu]# cat docker1.xml
<!–
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit docker1
or other application using the libvirt API.
–>

<domain type=’kvm’>
<name>docker1</name>
<memory unit=’KiB’>4096000</memory>
<currentMemory unit=’KiB’>4096000</currentMemory>
<vcpu placement=’static’>2</vcpu>
<os>
<type arch=’x86_64′ machine=’pc-i440fx-rhel7.0.0′>hvm</type>
<boot dev=’hd’/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode=’custom’ match=’exact’ check=’partial’>
<model fallback=’allow’>Skylake-Client-IBRS</model>
</cpu>
<clock offset=’utc’>
<timer name=’rtc’ tickpolicy=’catchup’/>
<timer name=’pit’ tickpolicy=’delay’/>
<timer name=’hpet’ present=’no’/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled=’no’/>
<suspend-to-disk enabled=’no’/>
</pm>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type=’file’ device=’disk’>
<driver name=’qemu’ type=’qcow2’/>
<source file=’/var/lib/libvirt/images/docker1.img’/>
<target dev=’vda’ bus=’virtio’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x07′ function=’0x0’/>
</disk>
<controller type=’usb’ index=’0′ model=’ich9-ehci1′>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x05′ function=’0x7’/>
</controller>
<controller type=’usb’ index=’0′ model=’ich9-uhci1′>
<master startport=’0’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x05′ function=’0x0′ multifunction=’on’/>
</controller>
<controller type=’usb’ index=’0′ model=’ich9-uhci2′>
<master startport=’2’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x05′ function=’0x1’/>
</controller>
<controller type=’usb’ index=’0′ model=’ich9-uhci3′>
<master startport=’4’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x05′ function=’0x2’/>
</controller>
<controller type=’pci’ index=’0′ model=’pci-root’/>
<controller type=’virtio-serial’ index=’0′>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x06′ function=’0x0’/>
</controller>
<interface type=’network’>
<source network=’vbr’/>
<model type=’virtio’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x03′ function=’0x0’/>
</interface>
<serial type=’pty’>
<target type=’isa-serial’ port=’0′>
<model name=’isa-serial’/>
</target>
</serial>
<console type=’pty’>
<target type=’serial’ port=’0’/>
</console>
<channel type=’unix’>
<target type=’virtio’ name=’org.qemu.guest_agent.0’/>
<address type=’virtio-serial’ controller=’0′ bus=’0′ port=’1’/>
</channel>
<channel type=’spicevmc’>
<target type=’virtio’ name=’com.redhat.spice.0’/>
<address type=’virtio-serial’ controller=’0′ bus=’0′ port=’2’/>
</channel>
<input type=’tablet’ bus=’usb’>
<address type=’usb’ bus=’0′ port=’1’/>
</input>
<input type=’mouse’ bus=’ps2’/>
<input type=’keyboard’ bus=’ps2’/>
<graphics type=’spice’ autoport=’yes’>
<listen type=’address’/>
<image compression=’off’/>
</graphics>
<sound model=’ich6′>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x04′ function=’0x0’/>
</sound>
<video>
<model type=’qxl’ ram=’65536′ vram=’65536′ vgamem=’16384′ heads=’1′ primary=’yes’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x02′ function=’0x0’/>
</video>
<redirdev bus=’usb’ type=’spicevmc’>
<address type=’usb’ bus=’0′ port=’2’/>
</redirdev>
<redirdev bus=’usb’ type=’spicevmc’>
<address type=’usb’ bus=’0′ port=’3’/>
</redirdev>
<memballoon model=’virtio’>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x08′ function=’0x0’/>
</memballoon>
</devices>
</domain>

virsh console分别连上去,开始准备docker环境
1)配置虚拟IP和主机名
docker1主机
[[email protected] ~]# cat /etc/hostname
docker1

[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE=”eth0″
NAME=”eth0″
ONBOOT=yes
IPV6INIT=no
BOOTPROTO=static
TYPE=Ethernet
IPADDR=”192.168.1.10″
PREFIX=”24″
GATEWAY=”192.168.1.254″

[[email protected] ~]# systemctl restart network
[[email protected] ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::5054:ff:fec2:e0da prefixlen 64 scopeid 0x20<link>
ether 52:54:00:c2:e0:da txqueuelen 1000 (Ethernet)
RX packets 217 bytes 16965 (16.5 KiB)
RX errors 0 dropped 11 overruns 0 frame 0
TX packets 67 bytes 5639 (5.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

docker2主机
[[email protected] qemu]# virsh console docker2
连接到域 docker2
换码符为 ^]

CentOS Linux 7 (Core)
Kernel 3.10.0-693.el7.x86_64 on an x86_64

localhost login: root
Password:
[[email protected] ~]# echo docker2 > /etc/hostname
[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE=”eth0″
NAME=”eth0″
ONBOOT=yes
IPV6INIT=no
BOOTPROTO=”static”
TYPE=Ethernet
IPADDR=”192.168.1.20″
PREFIX=”24″
GATEWAY=”192.168.1.254″
[[email protected] ~]# systemctl restart network
[[email protected] ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.20 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::5054:ff:fe26:5133 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:26:51:33 txqueuelen 1000 (Ethernet)
RX packets 599 bytes 38926 (38.0 KiB)
RX errors 0 dropped 9 overruns 0 frame 0
TX packets 119 bytes 9791 (9.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

为了方便下面的演示,把2台虚拟机都重启一下

配置YUM源(把自带的YUM源删掉)
(注意,第一个系统源要导入密钥,但是我们做模板机的时候已经导入了,所以就不做了)
DOCKER1
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo dvd.repo
[[email protected] yum.repos.d]# rm -rf dvd.repo
[[email protected] yum.repos.d]# vim /etc/yum.repos.d/local.repo
[[email protected] yum.repos.d]# cat /etc/yum.repos.d/local.repo
[local_repo]
name=CentOS-$releasever – Base
baseurl=”ftp://192.168.1.254/system”
enabled=1
gpgcheck=1
[loca]
name=local
baseurl=”ftp://192.168.1.254/docker”
enabled=1
gpgcheck=0
[[email protected] yum.repos.d]# yum repolist
已加载插件:fastestmirror
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
loca | 2.9 kB 00:00
local_repo | 3.6 kB 00:00
updates | 3.4 kB 00:00
(1/7): loca/primary_db | 3.4 kB 00:00
(2/7): local_repo/group_gz | 156 kB 00:00
(3/7): local_repo/primary_db | 5.7 MB 00:00
(4/7): base/7/x86_64/group_gz | 166 kB 00:00
(5/7): extras/7/x86_64/primary_db | 204 kB 00:00
(6/7): base/7/x86_64/primary_db | 5.9 MB 00:01
(7/7): updates/7/x86_64/primary_db | 6.0 MB 00:13
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: centos.ustc.edu.cn
源标识 源名称 状态
base/7/x86_64 CentOS-7 – Base 9,911
extras/7/x86_64 CentOS-7 – Extras 432
loca local 2
local_repo CentOS-7 – Base 9,591
updates/7/x86_64 CentOS-7 – Updates 1,551
repolist: 21,487

DOCKER2
[[email protected] yum.repos.d]# yum repolist
已加载插件:fastestmirror
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
loca | 2.9 kB 00:00
local_repo | 3.6 kB 00:00
updates | 3.4 kB 00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00
(2/4): extras/7/x86_64/primary_db | 204 kB 00:00
(3/4): base/7/x86_64/primary_db | 5.9 MB 00:01
(4/4): updates/7/x86_64/primary_db | 6.0 MB 00:12
Determining fastest mirrors
* base: mirrors.163.com
* extras: mirrors.cn99.com
* updates: mirrors.163.com
源标识 源名称 状态
base/7/x86_64 CentOS-7 – Base 9,911
extras/7/x86_64 CentOS-7 – Extras 432
loca local 2
local_repo CentOS-7 – Base 9,591
updates/7/x86_64 CentOS-7 – Updates 1,551
repolist: 21,487

安装DOCKER(2台虚拟机都要安装)
[[email protected] ~]# yum install -y docker-engine
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: centos.ustc.edu.cn
正在解决依赖关系
–> 正在检查事务
—> 软件包 docker-engine.x86_64.0.1.12.1-1.el7.centos 将被 安装
–> 正在处理依赖关系 docker-engine-selinux >= 1.12.1-1.el7.centos,它被软件包 docker-engine-1.12.1-1.el7.centos.x86_64 需要
–> 正在处理依赖关系 libcgroup,它被软件包 docker-engine-1.12.1-1.el7.centos.x86_64 需要
–> 正在处理依赖关系 libltdl.so.7()(64bit),它被软件包 docker-engine-1.12.1-1.el7.centos.x86_64 需要
–> 正在检查事务
—> 软件包 docker-engine-selinux.noarch.0.1.12.1-1.el7.centos 将被 安装
–> 正在处理依赖关系 policycoreutils-python,它被软件包 docker-engine-selinux-1.12.1-1.el7.centos.noarch 需要
—> 软件包 libcgroup.x86_64.0.0.41-15.el7 将被 安装
—> 软件包 libtool-ltdl.x86_64.0.2.4.2-22.el7_3 将被 安装
–> 正在检查事务
—> 软件包 policycoreutils-python.x86_64.0.2.5-22.el7 将被 安装
–> 正在处理依赖关系 policycoreutils = 2.5-22.el7,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 setools-libs >= 3.3.8-2,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libsemanage-python >= 2.5-9,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 audit-libs-python >= 2.1.3-4,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 python-IPy,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libqpol.so.1(VERS_1.4)(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libqpol.so.1(VERS_1.2)(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libapol.so.4(VERS_4.0)(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 checkpolicy,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libqpol.so.1()(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libapol.so.4()(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在检查事务
—> 软件包 audit-libs-python.x86_64.0.2.8.1-3.el7_5.1 将被 安装
–> 正在处理依赖关系 audit-libs(x86-64) = 2.8.1-3.el7_5.1,它被软件包 audit-libs-python-2.8.1-3.el7_5.1.x86_64 需要
—> 软件包 checkpolicy.x86_64.0.2.5-6.el7 将被 安装
—> 软件包 libsemanage-python.x86_64.0.2.5-11.el7 将被 安装
–> 正在处理依赖关系 libsemanage = 2.5-11.el7,它被软件包 libsemanage-python-2.5-11.el7.x86_64 需要
—> 软件包 policycoreutils.x86_64.0.2.5-17.1.el7 将被 升级
—> 软件包 policycoreutils.x86_64.0.2.5-22.el7 将被 更新
–> 正在处理依赖关系 libsepol >= 2.5-8,它被软件包 policycoreutils-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libselinux-utils >= 2.5-12,它被软件包 policycoreutils-2.5-22.el7.x86_64 需要
—> 软件包 python-IPy.noarch.0.0.75-6.el7 将被 安装
—> 软件包 setools-libs.x86_64.0.3.3.8-2.el7 将被 安装
–> 正在处理依赖关系 libselinux >= 2.5-12,它被软件包 setools-libs-3.3.8-2.el7.x86_64 需要
–> 正在检查事务
—> 软件包 audit-libs.x86_64.0.2.7.6-3.el7 将被 升级
–> 正在处理依赖关系 audit-libs(x86-64) = 2.7.6-3.el7,它被软件包 audit-2.7.6-3.el7.x86_64 需要
—> 软件包 audit-libs.x86_64.0.2.8.1-3.el7_5.1 将被 更新
—> 软件包 libselinux.x86_64.0.2.5-11.el7 将被 升级
–> 正在处理依赖关系 libselinux(x86-64) = 2.5-11.el7,它被软件包 libselinux-python-2.5-11.el7.x86_64 需要
—> 软件包 libselinux.x86_64.0.2.5-12.el7 将被 更新
—> 软件包 libselinux-utils.x86_64.0.2.5-11.el7 将被 升级
—> 软件包 libselinux-utils.x86_64.0.2.5-12.el7 将被 更新
—> 软件包 libsemanage.x86_64.0.2.5-8.el7 将被 升级
—> 软件包 libsemanage.x86_64.0.2.5-11.el7 将被 更新
—> 软件包 libsepol.x86_64.0.2.5-6.el7 将被 升级
—> 软件包 libsepol.x86_64.0.2.5-8.1.el7 将被 更新
–> 正在检查事务
—> 软件包 audit.x86_64.0.2.7.6-3.el7 将被 升级
—> 软件包 audit.x86_64.0.2.8.1-3.el7_5.1 将被 更新
—> 软件包 libselinux-python.x86_64.0.2.5-11.el7 将被 升级
—> 软件包 libselinux-python.x86_64.0.2.5-12.el7 将被 更新
–> 解决依赖关系完成

依赖关系解决

================================================================================
Package 架构 版本 源 大小
================================================================================
正在安装:
docker-engine x86_64 1.12.1-1.el7.centos loca 19 M
为依赖而安装:
audit-libs-python x86_64 2.8.1-3.el7_5.1 updates 75 k
checkpolicy x86_64 2.5-6.el7 base 294 k
docker-engine-selinux noarch 1.12.1-1.el7.centos loca 28 k
libcgroup x86_64 0.41-15.el7 base 65 k
libsemanage-python x86_64 2.5-11.el7 base 112 k
libtool-ltdl x86_64 2.4.2-22.el7_3 base 49 k
policycoreutils-python x86_64 2.5-22.el7 base 454 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.8-2.el7 base 619 k
为依赖而更新:
audit x86_64 2.8.1-3.el7_5.1 updates 247 k
audit-libs x86_64 2.8.1-3.el7_5.1 updates 99 k
libselinux x86_64 2.5-12.el7 base 162 k
libselinux-python x86_64 2.5-12.el7 base 235 k
libselinux-utils x86_64 2.5-12.el7 base 151 k
libsemanage x86_64 2.5-11.el7 base 150 k
libsepol x86_64 2.5-8.1.el7 base 297 k
policycoreutils x86_64 2.5-22.el7 base 867 k

事务概要
================================================================================
安装 1 软件包 (+9 依赖软件包)
升级 ( 8 依赖软件包)

总下载量:23 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/18): docker-engine-1.12.1-1.el7.centos.x86_64.rpm | 19 MB 00:00
(2/18): docker-engine-selinux-1.12.1-1.el7.centos.noarch.r | 28 kB 00:00
(3/18): audit-libs-2.8.1-3.el7_5.1.x86_64.rpm | 99 kB 00:00
(4/18): audit-2.8.1-3.el7_5.1.x86_64.rpm | 247 kB 00:00
(5/18): checkpolicy-2.5-6.el7.x86_64.rpm | 294 kB 00:00
(6/18): libcgroup-0.41-15.el7.x86_64.rpm | 65 kB 00:00
(7/18): libselinux-2.5-12.el7.x86_64.rpm | 162 kB 00:00
(8/18): libselinux-utils-2.5-12.el7.x86_64.rpm | 151 kB 00:00
(9/18): libsemanage-2.5-11.el7.x86_64.rpm | 150 kB 00:00
(10/18): libselinux-python-2.5-12.el7.x86_64.rpm | 235 kB 00:00
(11/18): libsemanage-python-2.5-11.el7.x86_64.rpm | 112 kB 00:00
(12/18): libsepol-2.5-8.1.el7.x86_64.rpm | 297 kB 00:00
(13/18): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm | 49 kB 00:00
(14/18): policycoreutils-2.5-22.el7.x86_64.rpm | 867 kB 00:00
(15/18): policycoreutils-python-2.5-22.el7.x86_64.rpm | 454 kB 00:00
(16/18): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00
(17/18): setools-libs-3.3.8-2.el7.x86_64.rpm | 619 kB 00:00
(18/18): audit-libs-python-2.8.1-3.el7_5.1.x86_64.rpm | 75 kB 00:01
——————————————————————————–
总计 15 MB/s | 23 MB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新 : libsepol-2.5-8.1.el7.x86_64 1/26
正在更新 : libselinux-2.5-12.el7.x86_64 2/26
正在更新 : audit-libs-2.8.1-3.el7_5.1.x86_64 3/26
正在更新 : libsemanage-2.5-11.el7.x86_64 4/26
正在更新 : libselinux-utils-2.5-12.el7.x86_64 5/26
正在更新 : policycoreutils-2.5-22.el7.x86_64 6/26
正在安装 : libcgroup-0.41-15.el7.x86_64 7/26
正在安装 : libsemanage-python-2.5-11.el7.x86_64 8/26
正在安装 : audit-libs-python-2.8.1-3.el7_5.1.x86_64 9/26
正在更新 : libselinux-python-2.5-12.el7.x86_64 10/26
正在安装 : setools-libs-3.3.8-2.el7.x86_64 11/26
正在安装 : checkpolicy-2.5-6.el7.x86_64 12/26
正在安装 : libtool-ltdl-2.4.2-22.el7_3.x86_64 13/26
正在安装 : python-IPy-0.75-6.el7.noarch 14/26
正在安装 : policycoreutils-python-2.5-22.el7.x86_64 15/26
正在安装 : docker-engine-selinux-1.12.1-1.el7.centos.noarch 16/26
setsebool: SELinux is disabled.
Re-declaration of type docker_t
Failed to create node
Bad type declaration at /etc/selinux/targeted/tmp/modules/400/docker/cil:1
/usr/sbin/semodule: Failed!
正在安装 : docker-engine-1.12.1-1.el7.centos.x86_64 17/26
正在更新 : audit-2.8.1-3.el7_5.1.x86_64 18/26
清理 : policycoreutils-2.5-17.1.el7.x86_64 19/26
清理 : libsemanage-2.5-8.el7.x86_64 20/26
清理 : libselinux-utils-2.5-11.el7.x86_64 21/26
清理 : audit-2.7.6-3.el7.x86_64 22/26
清理 : libselinux-python-2.5-11.el7.x86_64 23/26
清理 : libselinux-2.5-11.el7.x86_64 24/26
清理 : libsepol-2.5-6.el7.x86_64 25/26
清理 : audit-libs-2.7.6-3.el7.x86_64 26/26
验证中 : docker-engine-selinux-1.12.1-1.el7.centos.noarch 1/26
验证中 : docker-engine-1.12.1-1.el7.centos.x86_64 2/26
验证中 : libsemanage-2.5-11.el7.x86_64 3/26
验证中 : libselinux-python-2.5-12.el7.x86_64 4/26
验证中 : setools-libs-3.3.8-2.el7.x86_64 5/26
验证中 : audit-libs-python-2.8.1-3.el7_5.1.x86_64 6/26
验证中 : libsemanage-python-2.5-11.el7.x86_64 7/26
验证中 : policycoreutils-2.5-22.el7.x86_64 8/26
验证中 : audit-2.8.1-3.el7_5.1.x86_64 9/26
验证中 : policycoreutils-python-2.5-22.el7.x86_64 10/26
验证中 : python-IPy-0.75-6.el7.noarch 11/26
验证中 : libtool-ltdl-2.4.2-22.el7_3.x86_64 12/26
验证中 : libcgroup-0.41-15.el7.x86_64 13/26
验证中 : audit-libs-2.8.1-3.el7_5.1.x86_64 14/26
验证中 : libsepol-2.5-8.1.el7.x86_64 15/26
验证中 : libselinux-2.5-12.el7.x86_64 16/26
验证中 : libselinux-utils-2.5-12.el7.x86_64 17/26
验证中 : checkpolicy-2.5-6.el7.x86_64 18/26
验证中 : libselinux-utils-2.5-11.el7.x86_64 19/26
验证中 : libselinux-2.5-11.el7.x86_64 20/26
验证中 : audit-libs-2.7.6-3.el7.x86_64 21/26
验证中 : audit-2.7.6-3.el7.x86_64 22/26
验证中 : libsepol-2.5-6.el7.x86_64 23/26
验证中 : libsemanage-2.5-8.el7.x86_64 24/26
验证中 : libselinux-python-2.5-11.el7.x86_64 25/26
验证中 : policycoreutils-2.5-17.1.el7.x86_64 26/26

已安装:
docker-engine.x86_64 0:1.12.1-1.el7.centos

作为依赖被安装:
audit-libs-python.x86_64 0:2.8.1-3.el7_5.1
checkpolicy.x86_64 0:2.5-6.el7
docker-engine-selinux.noarch 0:1.12.1-1.el7.centos
libcgroup.x86_64 0:0.41-15.el7
libsemanage-python.x86_64 0:2.5-11.el7
libtool-ltdl.x86_64 0:2.4.2-22.el7_3
policycoreutils-python.x86_64 0:2.5-22.el7
python-IPy.noarch 0:0.75-6.el7
setools-libs.x86_64 0:3.3.8-2.el7

作为依赖被升级:
audit.x86_64 0:2.8.1-3.el7_5.1 audit-libs.x86_64 0:2.8.1-3.el7_5.1
libselinux.x86_64 0:2.5-12.el7 libselinux-python.x86_64 0:2.5-12.el7
libselinux-utils.x86_64 0:2.5-12.el7 libsemanage.x86_64 0:2.5-11.el7
libsepol.x86_64 0:2.5-8.1.el7 policycoreutils.x86_64 0:2.5-22.el7

完毕!
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

验证,能够看到docker0网卡说明一切正常
[[email protected] ~]# ifconfig docker0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:b2:94:cf:75 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[[email protected] ~]# docker version
Client:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built:
OS/Arch: linux/amd64

Server:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built:
OS/Arch: linux/amd64

第二台虚拟机
[[email protected] ~]# yum install -y docker-engine
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.cn99.com
* updates: mirrors.163.com
正在解决依赖关系
–> 正在检查事务
—> 软件包 docker-engine.x86_64.0.1.12.1-1.el7.centos 将被 安装
–> 正在处理依赖关系 docker-engine-selinux >= 1.12.1-1.el7.centos,它被软件包 docker-engine-1.12.1-1.el7.centos.x86_64 需要
–> 正在处理依赖关系 libcgroup,它被软件包 docker-engine-1.12.1-1.el7.centos.x86_64 需要
–> 正在处理依赖关系 libltdl.so.7()(64bit),它被软件包 docker-engine-1.12.1-1.el7.centos.x86_64 需要
–> 正在检查事务
—> 软件包 docker-engine-selinux.noarch.0.1.12.1-1.el7.centos 将被 安装
–> 正在处理依赖关系 policycoreutils-python,它被软件包 docker-engine-selinux-1.12.1-1.el7.centos.noarch 需要
—> 软件包 libcgroup.x86_64.0.0.41-15.el7 将被 安装
—> 软件包 libtool-ltdl.x86_64.0.2.4.2-22.el7_3 将被 安装
–> 正在检查事务
—> 软件包 policycoreutils-python.x86_64.0.2.5-22.el7 将被 安装
–> 正在处理依赖关系 policycoreutils = 2.5-22.el7,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 setools-libs >= 3.3.8-2,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libsemanage-python >= 2.5-9,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 audit-libs-python >= 2.1.3-4,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 python-IPy,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libqpol.so.1(VERS_1.4)(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libqpol.so.1(VERS_1.2)(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libapol.so.4(VERS_4.0)(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 checkpolicy,它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libqpol.so.1()(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libapol.so.4()(64bit),它被软件包 policycoreutils-python-2.5-22.el7.x86_64 需要
–> 正在检查事务
—> 软件包 audit-libs-python.x86_64.0.2.8.1-3.el7_5.1 将被 安装
–> 正在处理依赖关系 audit-libs(x86-64) = 2.8.1-3.el7_5.1,它被软件包 audit-libs-python-2.8.1-3.el7_5.1.x86_64 需要
—> 软件包 checkpolicy.x86_64.0.2.5-6.el7 将被 安装
—> 软件包 libsemanage-python.x86_64.0.2.5-11.el7 将被 安装
–> 正在处理依赖关系 libsemanage = 2.5-11.el7,它被软件包 libsemanage-python-2.5-11.el7.x86_64 需要
—> 软件包 policycoreutils.x86_64.0.2.5-17.1.el7 将被 升级
—> 软件包 policycoreutils.x86_64.0.2.5-22.el7 将被 更新
–> 正在处理依赖关系 libsepol >= 2.5-8,它被软件包 policycoreutils-2.5-22.el7.x86_64 需要
–> 正在处理依赖关系 libselinux-utils >= 2.5-12,它被软件包 policycoreutils-2.5-22.el7.x86_64 需要
—> 软件包 python-IPy.noarch.0.0.75-6.el7 将被 安装
—> 软件包 setools-libs.x86_64.0.3.3.8-2.el7 将被 安装
–> 正在处理依赖关系 libselinux >= 2.5-12,它被软件包 setools-libs-3.3.8-2.el7.x86_64 需要
–> 正在检查事务
—> 软件包 audit-libs.x86_64.0.2.7.6-3.el7 将被 升级
–> 正在处理依赖关系 audit-libs(x86-64) = 2.7.6-3.el7,它被软件包 audit-2.7.6-3.el7.x86_64 需要
—> 软件包 audit-libs.x86_64.0.2.8.1-3.el7_5.1 将被 更新
—> 软件包 libselinux.x86_64.0.2.5-11.el7 将被 升级
–> 正在处理依赖关系 libselinux(x86-64) = 2.5-11.el7,它被软件包 libselinux-python-2.5-11.el7.x86_64 需要
—> 软件包 libselinux.x86_64.0.2.5-12.el7 将被 更新
—> 软件包 libselinux-utils.x86_64.0.2.5-11.el7 将被 升级
—> 软件包 libselinux-utils.x86_64.0.2.5-12.el7 将被 更新
—> 软件包 libsemanage.x86_64.0.2.5-8.el7 将被 升级
—> 软件包 libsemanage.x86_64.0.2.5-11.el7 将被 更新
—> 软件包 libsepol.x86_64.0.2.5-6.el7 将被 升级
—> 软件包 libsepol.x86_64.0.2.5-8.1.el7 将被 更新
–> 正在检查事务
—> 软件包 audit.x86_64.0.2.7.6-3.el7 将被 升级
—> 软件包 audit.x86_64.0.2.8.1-3.el7_5.1 将被 更新
—> 软件包 libselinux-python.x86_64.0.2.5-11.el7 将被 升级
—> 软件包 libselinux-python.x86_64.0.2.5-12.el7 将被 更新
–> 解决依赖关系完成

依赖关系解决

======================================================================================================
Package 架构 版本 源 大小
======================================================================================================
正在安装:
docker-engine x86_64 1.12.1-1.el7.centos loca 19 M
为依赖而安装:
audit-libs-python x86_64 2.8.1-3.el7_5.1 updates 75 k
checkpolicy x86_64 2.5-6.el7 base 294 k
docker-engine-selinux noarch 1.12.1-1.el7.centos loca 28 k
libcgroup x86_64 0.41-15.el7 base 65 k
libsemanage-python x86_64 2.5-11.el7 base 112 k
libtool-ltdl x86_64 2.4.2-22.el7_3 base 49 k
policycoreutils-python x86_64 2.5-22.el7 base 454 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.8-2.el7 base 619 k
为依赖而更新:
audit x86_64 2.8.1-3.el7_5.1 updates 247 k
audit-libs x86_64 2.8.1-3.el7_5.1 updates 99 k
libselinux x86_64 2.5-12.el7 base 162 k
libselinux-python x86_64 2.5-12.el7 base 235 k
libselinux-utils x86_64 2.5-12.el7 base 151 k
libsemanage x86_64 2.5-11.el7 base 150 k
libsepol x86_64 2.5-8.1.el7 base 297 k
policycoreutils x86_64 2.5-22.el7 base 867 k

事务概要
======================================================================================================
安装 1 软件包 (+9 依赖软件包)
升级 ( 8 依赖软件包)

总下载量:23 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/18): docker-engine-1.12.1-1.el7.centos.x86_64.rpm | 19 MB 00:00:00
(2/18): docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm | 28 kB 00:00:00
(3/18): audit-libs-2.8.1-3.el7_5.1.x86_64.rpm | 99 kB 00:00:00
(4/18): audit-2.8.1-3.el7_5.1.x86_64.rpm | 247 kB 00:00:00
(5/18): audit-libs-python-2.8.1-3.el7_5.1.x86_64.rpm | 75 kB 00:00:00
(6/18): libcgroup-0.41-15.el7.x86_64.rpm | 65 kB 00:00:00
(7/18): checkpolicy-2.5-6.el7.x86_64.rpm | 294 kB 00:00:00
(8/18): libselinux-python-2.5-12.el7.x86_64.rpm | 235 kB 00:00:00
(9/18): libselinux-2.5-12.el7.x86_64.rpm | 162 kB 00:00:00
(10/18): libselinux-utils-2.5-12.el7.x86_64.rpm | 151 kB 00:00:00
(11/18): libsemanage-2.5-11.el7.x86_64.rpm | 150 kB 00:00:00
(12/18): libsemanage-python-2.5-11.el7.x86_64.rpm | 112 kB 00:00:00
(13/18): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm | 49 kB 00:00:00
(14/18): libsepol-2.5-8.1.el7.x86_64.rpm | 297 kB 00:00:00
(15/18): policycoreutils-2.5-22.el7.x86_64.rpm | 867 kB 00:00:00
(16/18): policycoreutils-python-2.5-22.el7.x86_64.rpm | 454 kB 00:00:00
(17/18): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00:00
(18/18): setools-libs-3.3.8-2.el7.x86_64.rpm | 619 kB 00:00:00
——————————————————————————————————
总计 11 MB/s | 23 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新 : libsepol-2.5-8.1.el7.x86_64 1/26
正在更新 : libselinux-2.5-12.el7.x86_64 2/26
正在更新 : audit-libs-2.8.1-3.el7_5.1.x86_64 3/26
正在更新 : libsemanage-2.5-11.el7.x86_64 4/26
正在更新 : libselinux-utils-2.5-12.el7.x86_64 5/26
正在更新 : policycoreutils-2.5-22.el7.x86_64 6/26
正在安装 : libcgroup-0.41-15.el7.x86_64 7/26
正在安装 : libsemanage-python-2.5-11.el7.x86_64 8/26
正在安装 : audit-libs-python-2.8.1-3.el7_5.1.x86_64 9/26
正在更新 : libselinux-python-2.5-12.el7.x86_64 10/26
正在安装 : setools-libs-3.3.8-2.el7.x86_64 11/26
正在安装 : checkpolicy-2.5-6.el7.x86_64 12/26
正在安装 : libtool-ltdl-2.4.2-22.el7_3.x86_64 13/26
正在安装 : python-IPy-0.75-6.el7.noarch 14/26
正在安装 : policycoreutils-python-2.5-22.el7.x86_64 15/26
正在安装 : docker-engine-selinux-1.12.1-1.el7.centos.noarch 16/26
setsebool: SELinux is disabled.
Re-declaration of type docker_t
Failed to create node
Bad type declaration at /etc/selinux/targeted/tmp/modules/400/docker/cil:1
/usr/sbin/semodule: Failed!
正在安装 : docker-engine-1.12.1-1.el7.centos.x86_64 17/26
正在更新 : audit-2.8.1-3.el7_5.1.x86_64 18/26
清理 : policycoreutils-2.5-17.1.el7.x86_64 19/26
清理 : libsemanage-2.5-8.el7.x86_64 20/26
清理 : libselinux-utils-2.5-11.el7.x86_64 21/26
清理 : audit-2.7.6-3.el7.x86_64 22/26
清理 : libselinux-python-2.5-11.el7.x86_64 23/26
清理 : libselinux-2.5-11.el7.x86_64 24/26
清理 : libsepol-2.5-6.el7.x86_64 25/26
清理 : audit-libs-2.7.6-3.el7.x86_64 26/26
验证中 : docker-engine-selinux-1.12.1-1.el7.centos.noarch 1/26
验证中 : docker-engine-1.12.1-1.el7.centos.x86_64 2/26
验证中 : libsemanage-2.5-11.el7.x86_64 3/26
验证中 : libselinux-python-2.5-12.el7.x86_64 4/26
验证中 : setools-libs-3.3.8-2.el7.x86_64 5/26
验证中 : audit-libs-python-2.8.1-3.el7_5.1.x86_64 6/26
验证中 : libsemanage-python-2.5-11.el7.x86_64 7/26
验证中 : policycoreutils-2.5-22.el7.x86_64 8/26
验证中 : audit-2.8.1-3.el7_5.1.x86_64 9/26
验证中 : policycoreutils-python-2.5-22.el7.x86_64 10/26
验证中 : python-IPy-0.75-6.el7.noarch 11/26
验证中 : libtool-ltdl-2.4.2-22.el7_3.x86_64 12/26
验证中 : libcgroup-0.41-15.el7.x86_64 13/26
验证中 : audit-libs-2.8.1-3.el7_5.1.x86_64 14/26
验证中 : libsepol-2.5-8.1.el7.x86_64 15/26
验证中 : libselinux-2.5-12.el7.x86_64 16/26
验证中 : libselinux-utils-2.5-12.el7.x86_64 17/26
验证中 : checkpolicy-2.5-6.el7.x86_64 18/26
验证中 : libselinux-utils-2.5-11.el7.x86_64 19/26
验证中 : libselinux-2.5-11.el7.x86_64 20/26
验证中 : audit-libs-2.7.6-3.el7.x86_64 21/26
验证中 : audit-2.7.6-3.el7.x86_64 22/26
验证中 : libsepol-2.5-6.el7.x86_64 23/26
验证中 : libsemanage-2.5-8.el7.x86_64 24/26
验证中 : libselinux-python-2.5-11.el7.x86_64 25/26
验证中 : policycoreutils-2.5-17.1.el7.x86_64 26/26

已安装:
docker-engine.x86_64 0:1.12.1-1.el7.centos

作为依赖被安装:
audit-libs-python.x86_64 0:2.8.1-3.el7_5.1 checkpolicy.x86_64 0:2.5-6.el7
docker-engine-selinux.noarch 0:1.12.1-1.el7.centos libcgroup.x86_64 0:0.41-15.el7
libsemanage-python.x86_64 0:2.5-11.el7 libtool-ltdl.x86_64 0:2.4.2-22.el7_3
policycoreutils-python.x86_64 0:2.5-22.el7 python-IPy.noarch 0:0.75-6.el7
setools-libs.x86_64 0:3.3.8-2.el7

作为依赖被升级:
audit.x86_64 0:2.8.1-3.el7_5.1 audit-libs.x86_64 0:2.8.1-3.el7_5.1
libselinux.x86_64 0:2.5-12.el7 libselinux-python.x86_64 0:2.5-12.el7
libselinux-utils.x86_64 0:2.5-12.el7 libsemanage.x86_64 0:2.5-11.el7
libsepol.x86_64 0:2.5-8.1.el7 policycoreutils.x86_64 0:2.5-22.el7

完毕!
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[[email protected] ~]# ifconfig docker0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:28:ff:5c:c9 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[[email protected] ~]# docker version
Client:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built:
OS/Arch: linux/amd64

Server:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built:
OS/Arch: linux/amd64

2 案例2:镜像基本操作
2.1 问题

本案例要求熟悉镜像的基本操作:
导入镜像
导出镜像
启动镜像
2.2 步骤

实现此案例需要按照如下步骤进行。
步骤一:docker镜像

1)下载镜像
[[email protected] ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
8c5a7da1afbc: Pull complete
Digest: sha256:cb63aa0641a885f54de20f61d152187419e8f6b159ed11a251a09d115fdff9bd
Status: Downloaded newer image for busybox:latest
2)上传镜像
[[email protected] ~]# docker push busybox
3)查看镜像
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest e1ddd7948a1c 4 weeks ago 1.163 MB
4)查找busybox镜像
[[email protected] ~]# docker search busybox
5)导出busybox镜像为busybox.tar
[[email protected] ~]# docker save busybox:latest >busybox.tar
[[email protected] ~]# ls
busybox.tar
6)导入镜像
[[email protected] ~]# scp busybox.tar 192.168.1.20:/root
[[email protected] ~]# ls
busybox.tar
[[email protected] ~]# docker load <busybox.tar
f9d9e4e6e2f0: Loading layer [==================================================>] 1.378 MB/1.378 MB
Loaded image: busybox:latest[=> ] 32.77 kB/1.378 MB
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest e1ddd7948a1c 4 weeks ago 1.163 MB
7)删除镜像
[[email protected] ~]# docker rmi busybox
Untagged: busybox:latest
Deleted: sha256:e1ddd7948a1c31709a23cc5b7dfe96e55fc364f90e1cebcde0773a1b5a30dcda
Deleted: sha256:f9d9e4e6e2f0689cd752390e14ade48b0ec6f2a488a05af5ab2f9ccaf54c299d
步骤二:一次性导入多个镜像
[[email protected] ~]# yum -y install unzip
[[email protected] ~]# unzip docker_images.zip
Archive: docker_images.zip
creating: docker_images/
inflating: docker_images/nginx.tar
inflating: docker_images/redis.tar
inflating: docker_images/centos.tar
inflating: docker_images/registry.tar
inflating: docker_images/ubuntu.tar
[[email protected] ~]# ls
busybox.tar docker_images docker_images.zip eip
[[email protected] ~]# cd docker_images
[[email protected] docker_images]# ls
centos.tar nginx.tar redis.tar registry.tar ubuntu.tar
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest e1ddd7948a1c 4 weeks ago 1.163 MB
[[email protected] docker_images]# for i in *; do docker load <$i; done
步骤三:启动镜像

1)启动centos镜像生成一个容器
启动镜像时若不知道后面的命令加什么:
1、可以猜(如:/bin/bash、/bin/sh)
2、可以不加后面的命令,默认启动
[[email protected] docker_images]# docker run -it centos /bin/bash
[[email protected] /]# ls /
anaconda-post.log bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[[email protected] /]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Sources.repo CentOS-fasttrack.repo
CentOS-CR.repo CentOS-Media.repo CentOS-Vault.repo
[[email protected] yum.repos.d]# rm -rf C*
[[email protected] yum.repos.d]# ls
[[email protected] yum.repos.d]#vi dvd.repo //在容器里面配置一个yum源
[local]
name=local
baseurl=ftp://192.168.1.254/system
enable=1
gpgcheck=0
[[email protected] yum.repos.d]# yum -y install net-tools //安装软件
[[email protected] yum.repos.d]# exit
exit

代码如下
下载镜像
[[email protected] ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
90e01955edcd: Pull complete
Digest: sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812
Status: Downloaded newer image for busybox:latest

上传镜像
[[email protected] ~]# docker push busybox
The push refers to a repository [docker.io/library/busybox]
8a788232037e: Layer already exists
unauthorized: authentication required

查看镜像
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 13 days ago 1.154 MB

查找busybox镜像
[[email protected] ~]# docker search busybox
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
busybox Busybox base image. 1380 [OK]
progrium/busybox 68 [OK]
hypriot/rpi-busybox-httpd Raspberry Pi compatible Docker Image with … 44
radial/busyboxplus Full-chain, Internet enabled, busybox made… 20 [OK]
hypriot/armhf-busybox Busybox base image for ARM. 9
arm32v7/busybox Busybox base image. 6
yauritux/busybox-curl Busybox with CURL 4
armhf/busybox Busybox base image. 4
prom/busybox Prometheus Busybox Docker base images 2 [OK]
p7ppc64/busybox Busybox base image for ppc64. 2
odise/busybox-curl 2 [OK]
armel/busybox Busybox base image. 2
s390x/busybox Busybox base image. 2
onsi/grace-busybox 2
i386/busybox Busybox base image. 2
aarch64/busybox Busybox base image. 2
sequenceiq/busybox 2 [OK]
arm64v8/busybox Busybox base image. 1
ppc64le/busybox Busybox base image. 1
spotify/busybox Spotify fork of https://hub.docker.com/_/b… 1
amd64/busybox Busybox base image. 0
trollin/busybox 0
ggtools/busybox-ubuntu Busybox ubuntu version with extra goodies 0 [OK]
cfgarden/garden-busybox 0
concourse/busyboxplus 0
[[email protected] ~]#

导出busybox镜像为busybox.tar
[[email protected] ~]# docker save busybox:latest > busybox.tar
[[email protected] ~]# ls
busybox.tar RPM-GPG-KEY-CentOS-7
[[email protected] ~]# ll -h
总用量 1.4M
-rw-r–r– 1 root root 1.4M 10月 16 15:03 busybox.tar
-rw-r–r–. 1 root root 1.7K 12月 10 2015 RPM-GPG-KEY-CentOS-7

导入busybox镜像
把上面保存的镜像传给DOCKER2虚拟机
[[email protected] ~]# scp busybox.tar 192.168.1.20:/root
The authenticity of host ‘192.168.1.20 (192.168.1.20)’ can’t be established.
ECDSA key fingerprint is SHA256:J7RGnsjDzAzWQXirPkg41IuH/Yqeu8/0Wd/RC7EOLvM.
ECDSA key fingerprint is MD5:4c:19:01:4f:77:32:04:27:c7:68:9a:7c:83:92:4d:39.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.1.20’ (ECDSA) to the list of known hosts.
[email protected]’s password:
busybox.tar

到另外一台虚拟机上面去操作
[[email protected] ~]# ll -h
总用量 1.4M
-rw-r–r– 1 root root 1.4M 10月 16 15:08 busybox.tar
-rw-r–r–. 1 root root 1.7K 12月 10 2015 RPM-GPG-KEY-CentOS-7

[[email protected] ~]# docker load < busybox.tar
8a788232037e: Loading layer 1.37 MB/1.37 MB
Loaded image: busybox:latest
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 13 days ago 1.154 MB

删除镜像
[[email protected] ~]# docker rmi busybox
Untagged: busybox:latest
Deleted: sha256:59788edf1f3e78cd0ebe6ce1446e9d10788225db3dedcfd1a59f764bad2b2690
Deleted: sha256:8a788232037eaf17794408ff3df6b922a1aedf9ef8de36afdae3ed0b0381907b
[[email protected] ~]#

一次性导入多个镜像
先把真机上事先准备好的多个镜像传到虚拟机上面
[[email protected] cloud 4]# ll
总用量 104624
drwxrwxrwx 2 root root 4096 8月 11 21:37 docker 1
-rwxrwxrwx 1 root root 633921 7月 13 00:53 NSD_CLOUD_04.pdf
-rwxrwxrwx 1 root root 106493440 7月 13 00:53 small.img
[[email protected] cloud 4]# cd docker\ 1/
[[email protected] docker 1]# ll
总用量 271692
-rwxrwxrwx 1 root root 4168 7月 13 01:01 docker_01.txt
-rwxrwxrwx 1 root root 19917380 7月 13 01:01 docker-engine-1.12.1-1.el7.centos.x86_64.rpm
-rwxrwxrwx 1 root root 28860 7月 13 01:01 docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm
-rwxrwxrwx 1 root root 258246973 7月 13 01:02 docker_images.zip
[[email protected] docker 1]# scp docker_images.zip 192.168.1.10:/root
[email protected]’s password:
docker_images.zip

DOCKER1上面,先安装解压软件
[[email protected] ~]# yum install -y unzip
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: centos.ustc.edu.cn
正在解决依赖关系
–> 正在检查事务
—> 软件包 unzip.x86_64.0.6.0-19.el7 将被 安装
–> 解决依赖关系完成

依赖关系解决

======================================================================================================
Package 架构 版本 源 大小
======================================================================================================
正在安装:
unzip x86_64 6.0-19.el7 base 170 k

事务概要
======================================================================================================
安装 1 软件包

总下载量:170 k
安装大小:365 k
Downloading packages:
unzip-6.0-19.el7.x86_64.rpm | 170 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : unzip-6.0-19.el7.x86_64 1/1
验证中 : unzip-6.0-19.el7.x86_64 1/1

已安装:
unzip.x86_64 0:6.0-19.el7

完毕!

解压,然后进去看一眼

[[email protected] ~]# ll -h
总用量 248M
-rw-r–r– 1 root root 1.4M 10月 16 15:03 busybox.tar
-rwxr-xr-x 1 root root 247M 10月 16 15:15 docker_images.zip
-rw-r–r–. 1 root root 1.7K 12月 10 2015 RPM-GPG-KEY-CentOS-7
[[email protected] ~]# unzip docker_images.zip
Archive: docker_images.zip
creating: docker_images/
inflating: docker_images/nginx.tar
inflating: docker_images/redis.tar
inflating: docker_images/centos.tar
inflating: docker_images/registry.tar
inflating: docker_images/ubuntu.tar
[[email protected] ~]# ll -h
总用量 248M
-rw-r–r– 1 root root 1.4M 10月 16 15:03 busybox.tar
drwxr-xr-x 2 root root 96 5月 16 20:33 docker_images
-rwxr-xr-x 1 root root 247M 10月 16 15:15 docker_images.zip
-rw-r–r–. 1 root root 1.7K 12月 10 2015 RPM-GPG-KEY-CentOS-7
[[email protected] ~]# cd docker_images/
[[email protected] docker_images]# ls
centos.tar nginx.tar redis.tar registry.tar ubuntu.tar
[[email protected] docker_images]#
[[email protected] docker_images]# ll -h
总用量 672M
-rw-r–r– 1 root root 198M 5月 16 20:28 centos.tar
-rw-r–r– 1 root root 181M 10月 19 2016 nginx.tar
-rw-r–r– 1 root root 181M 10月 19 2016 redis.tar
-rw-r–r– 1 root root 35M 5月 16 20:28 registry.tar
-rw-r–r– 1 root root 79M 5月 16 20:33 ubuntu.tar

开始导入镜像,然后查看确认
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 13 days ago 1.154 MB
[[email protected] docker_images]# for i in * ; do docker load < $i ; done
43e653f84b79: Loading layer 207.2 MB/207.2 MB
Loaded image: centos:latest
142a601d9793: Loading layer 128.9 MB/128.9 MB
40e298e9673a: Loading layer 60.57 MB/60.57 MB
8d8bfe3cd5e4: Loading layer 3.584 kB/3.584 kB
Loaded image: nginx:latest
1cc8aacad4a1: Loading layer 344.6 kB/344.6 kB
40ef78f2da08: Loading layer 41.21 MB/41.21 MB
652c8a715c4f: Loading layer 2.703 MB/2.703 MB
fa4e25f53e04: Loading layer 16.46 MB/16.46 MB
c215f3ad270b: Loading layer 1.536 kB/1.536 kB
644be81b61f9: Loading layer 3.584 kB/3.584 kB
Loaded image: redis:latest
e53f74215d12: Loading layer 5.06 MB/5.06 MB
febf19f93653: Loading layer 7.894 MB/7.894 MB
59e80739ed3f: Loading layer 22.79 MB/22.79 MB
621c2399d41a: Loading layer 3.584 kB/3.584 kB
9113493eaae1: Loading layer 2.048 kB/2.048 kB
Loaded image: registry:latest
65bdd50ee76a: Loading layer 82.09 MB/82.09 MB
ec75999a0cb1: Loading layer 15.87 kB/15.87 kB
67885e448177: Loading layer 8.192 kB/8.192 kB
8db5f072feec: Loading layer 5.632 kB/5.632 kB
059ad60bcacf: Loading layer 3.072 kB/3.072 kB
Loaded image: ubuntu:latest
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 13 days ago 1.154 MB
ubuntu latest 452a96d81c30 5 months ago 79.62 MB
centos latest e934aafc2206 6 months ago 198.6 MB
registry latest d1fd7d86a825 9 months ago 33.26 MB
nginx latest a5311a310510 2 years ago 181.4 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB

启动镜像,进去看一下
[[email protected] docker_images]# docker run -it centos /bin/bash
[[email protected] /]# ls /
anaconda-post.log dev home lib64 mnt proc run srv tmp var
bin etc lib media opt root sbin sys usr
[[email protected] /]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Sources.repo CentOS-fasttrack.repo
CentOS-CR.repo CentOS-Media.repo CentOS-Vault.repo
[[email protected] yum.repos.d]# rm -rf *
[[email protected] yum.repos.d]# ls
[[email protected] yum.repos.d]# vi dvd.repo
[[email protected] yum.repos.d]# cat dvd.repo
[local]
name=local
baseurl=ftp://192.168.1.254/system
enable=1
gpgcheck=0

可以看到,常用的网络命令都没有,所以装一个
[[email protected] yum.repos.d]# ifconfig
bash: ifconfig: command not found
[[email protected] yum.repos.d]# ip a s
bash: ip: command not found

[[email protected] yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, ovl
local | 3.6 kB 00:00:00
(1/2): local/group_gz | 156 kB 00:00:00
(2/2): local/primary_db | 5.7 MB 00:00:00
Determining fastest mirrors
repo id repo name status
local local 9591
repolist: 9591
[[email protected] yum.repos.d]# yum -y install net-tools
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
Resolving Dependencies
–> Running transaction check
—> Package net-tools.x86_64 0:2.0-0.22.20131004git.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================
Package Arch Version Repository Size
======================================================================================================
Installing:
net-tools x86_64 2.0-0.22.20131004git.el7 local 305 k

Transaction Summary
======================================================================================================
Install 1 Package

Total download size: 305 k
Installed size: 917 k
Downloading packages:
net-tools-2.0-0.22.20131004git.el7.x86_64.rpm | 305 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : net-tools-2.0-0.22.20131004git.el7.x86_64 1/1
Verifying : net-tools-2.0-0.22.20131004git.el7.x86_64 1/1

Installed:
net-tools.x86_64 0:2.0-0.22.20131004git.el7

Complete!

查看IP
[[email protected] yum.repos.d]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:2 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 362 bytes 6525262 (6.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 276 bytes 19443 (18.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[[email protected] yum.repos.d]#
[[email protected] yum.repos.d]# exit
exit
退出来看虚拟机1的docker0网桥,可以看到这是个docker0网桥就是内部镜像使用的网桥
[[email protected] docker_images]# ifconfig docker0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:b2ff:fe94:cf75 prefixlen 64 scopeid 0x20<link>
ether 02:42:b2:94:cf:75 txqueuelen 0 (Ethernet)
RX packets 276 bytes 15579 (15.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 354 bytes 6524614 (6.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

3 案例3:镜像与容器常用指令
3.1 问题

本案例要求掌握镜像与容器的常用命令:
镜像常用指令练习
容器常用指令练习
3.2 步骤

实现此案例需要按照如下步骤进行。
步骤一:镜像常用命令

1)查看后台运行的容器
[[email protected] ~]# docker run -d nginx //启动nginx的镜像
[[email protected] ~]# docker ps //查看后台运行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
56ec8154f8e0 nginx:latest “nginx -g ‘daemon off” 17 minutes ago Up 12 minutes 80/tcp, 443/tcp zen_darwin
2)只显示容器ID
[[email protected] docker_images]# docker ps -q
56ec8154f8e0
85c6b0b62235
f7ee40a87af5
3)显示所有的容器,包括没有启动的
[[email protected] docker_images]# docker ps -a
4)显示所有的容器ID
[[email protected] docker_images]# docker ps -qa
56ec8154f8e0
2b68c3960737
85c6b0b62235
f7ee40a87af5
b261be571648
fb2fb8c3d7a8
5)查看centos镜像历史(制作过程),如图-2所示:
[[email protected] docker_images]# docker history centos

图-2
7)删除镜像,启动容器时删除镜像会失败,先删除容器,再删除镜像
格式:docker rmi 镜像名
[[email protected] docker_images]# docker rmi nginx //nginx为镜像名
Error response from daemon: conflict: unable to remove repository reference “nginx” (must force) – container 4f83871aa42e is using its referenced image a5311a310510 //删除时报错
[[email protected] docker_images]# docker stop 4f
4f
[[email protected] docker_images]# docker rm 4f
4f
[[email protected] docker_images]# docker rmi nginx //成功删除
Untagged: nginx:latest
Deleted: sha256:d1fd7d86a8257f3404f92c4474fb3353076883062d64a09232d95d940627459d
Deleted: sha256:4d765aea84ce4f56bd623e4fd38dec996a259af3418e2466d0e2067ed0ae8aa6
Deleted: sha256:5d385be69c9c4ce5538e12e6e677727ebf19ca0afaff6f035d8043b5e413003a
Deleted: sha256:adb712878b60bd7ed8ce661c91eb3ac30f41b67bfafed321395863051596a8e9
Deleted: sha256:55a50a618c1b76f784b0b68a0b3d70db93b353fb03227ea6bd87f794cad92917
Deleted: sha256:e53f74215d12318372e4412d0f0eb3908e17db25c6185f670db49aef5271f91f
8)修改镜像的名称和标签,默认标签为latest
[[email protected] docker_images]# docker tag centos:latest cen:v1
9)查看镜像的底层信息,如图-3所示:
[[email protected] docker_images]# docker inspect centos

代码如下
1)查看并启动镜像
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 2 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 5 months ago 79.62 MB
centos latest e934aafc2206 6 months ago 198.6 MB
registry latest d1fd7d86a825 9 months ago 33.26 MB
nginx latest a5311a310510 2 years ago 181.4 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB
[[email protected] docker_images]# docker run -d nginx
ebe2c559597be71252e683753a41aa4ed07ac15c054c707d5dd3b5e3e64f0b19
[[email protected] docker_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ebe2c559597b nginx “nginx -g ‘daemon off” 6 seconds ago Up 3 seconds 80/tcp, 443/tcp boring_lamarr
或者也可以只显示容器的ID
[[email protected] docker_images]# docker ps -q
ebe2c559597b

2)显示所有的容器,包括没有启动的
[[email protected] docker_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ebe2c559597b nginx “nginx -g ‘daemon off” About a minute ago Up About a minute 80/tcp, 443/tcp boring_lamarr
700bd88a787b centos “/bin/bash” 19 hours ago Exited (0) 19 hours ago lonely_dubinsky
或者只查看容器的ID
[[email protected] docker_images]# docker ps -qa
ebe2c559597b
700bd88a787b

3)查看容器的制作过程
[[email protected] docker_images]# docker history centos
IMAGE CREATED CREATED BY SIZE COMMENT
e934aafc2206 6 months ago /bin/sh -c #(nop) CMD [“/bin/bash”] 0 B
<missing> 6 months ago /bin/sh -c #(nop) LABEL org.label-schema.sch 0 B
<missing> 6 months ago /bin/sh -c #(nop) ADD file:f755805244a649ecca 198.6 MB

4)删除镜像,要先删除该镜像启动的容器,再删除镜像
先查一下nginx的ID,前两位是eb
[[email protected] docker_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ebe2c559597b nginx “nginx -g ‘daemon off” 3 minutes ago Up 3 minutes 80/tcp, 443/tcp boring_lamarr
[[email protected] docker_images]#
直接删除是失败的
[[email protected] docker_images]# docker rmi nginx
Error response from daemon: conflict: unable to remove repository reference “nginx” (must force) – container ebe2c559597b is using its referenced image a5311a310510
先把容器eb停止并删除
[[email protected] docker_images]# docker stop eb
eb
[[email protected] docker_images]# docker rm eb
eb
再删除镜像nginx就可以成功了
[[email protected] docker_images]# docker rmi nginx
Untagged: nginx:latest
Deleted: sha256:a5311a310510e5eaff3cfbb22b65d9ce11ddc15e266833909551334d48491921
Deleted: sha256:793457e70277c832d031ab9923a2820215fb247379880a4d93c17f64812bc531
Deleted: sha256:5a26610d59c221d133ad969ef3dcedd17a360df70d00e377d5b01c50f55bfa71

5)修改镜像名和标签,默认所有的标签的latest
我们把centos latest修改成 cen v1
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 2 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 5 months ago 79.62 MB
centos latest e934aafc2206 6 months ago 198.6 MB
registry latest d1fd7d86a825 9 months ago 33.26 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB
[[email protected] docker_images]# docker tag centos:latest cen:v1
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 2 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 5 months ago 79.62 MB
cen v1 e934aafc2206 6 months ago 198.6 MB
centos latest e934aafc2206 6 months ago 198.6 MB
registry latest d1fd7d86a825 9 months ago 33.26 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB

查看镜像的底层信息
[[email protected] docker_images]# docker inspect centos
[
{
“Id”: “sha256:e934aafc22064b7322c0250f1e32e5ce93b2d19b356f4537f5864bd102e8531f”,
“RepoTags”: [
“cen:v1”,
“centos:latest”
],
“RepoDigests”: [],
“Parent”: “”,
“Comment”: “”,
“Created”: “2018-04-06T21:01:51.215822656Z”,
“Container”: “20e7cee1d3f15879fb54cb361e2ceb3b4cd260f90e51202feec140f1aa9d8527”,
“ContainerConfig”: {
“Hostname”: “20e7cee1d3f1”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
],
“Cmd”: [
“/bin/sh”,
“-c”,
“#(nop) “,
“CMD [\”/bin/bash\”]”
],
“ArgsEscaped”: true,
“Image”: “sha256:33993dd9c7556016a6f54c12969e07640d6737cdfe9b98391ad38e9a5f6c4217”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {
“org.label-schema.schema-version”: “= 1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20180402”
}
},
“DockerVersion”: “17.06.2-ce”,
“Author”: “”,
“Config”: {
“Hostname”: “”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
],
“Cmd”: [
“/bin/bash”
],
“ArgsEscaped”: true,
“Image”: “sha256:33993dd9c7556016a6f54c12969e07640d6737cdfe9b98391ad38e9a5f6c4217”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {
“org.label-schema.schema-version”: “= 1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20180402”
}
},
“Architecture”: “amd64”,
“Os”: “linux”,
“Size”: 198611378,
“VirtualSize”: 198611378,
“GraphDriver”: {
“Name”: “devicemapper”,
“Data”: {
“DeviceId”: “3”,
“DeviceName”: “docker-253:1-8388784-dc23f9921beb8944d203bb7973c15a45d0acb2bac97b0b4c68ad71c10cdd6c2d”,
“DeviceSize”: “10737418240”
}
},
“RootFS”: {
“Type”: “layers”,
“Layers”: [
“sha256:43e653f84b79ba52711b0f726ff5a7fd1162ae9df4be76ca1de8370b8bbf9bb0”
]
}
}
]

改名后删除镜像
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 2 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 5 months ago 79.62 MB
cen v1 e934aafc2206 6 months ago 198.6 MB
registry latest d1fd7d86a825 9 months ago 33.26 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB
[[email protected] docker_images]# docker tag cen:v1 centos:latest
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 2 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 5 months ago 79.62 MB
cen v1 e934aafc2206 6 months ago 198.6 MB
centos latest e934aafc2206 6 months ago 198.6 MB
registry latest d1fd7d86a825 9 months ago 33.26 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB
删掉刚才改的名的镜像
[[email protected] docker_images]# docker rmi cen:v1
Untagged: cen:v1
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 2 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 5 months ago 79.62 MB
centos latest e934aafc2206 6 months ago 198.6 MB
registry latest d1fd7d86a825 9 months ago 33.26 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB
直接删除镜像centos是删除不掉的,因为有容器了,所以要先删除容器,再删除镜像
[[email protected] docker_images]# docker rmi centos
Error response from daemon: conflict: unable to remove repository reference “centos” (must force) – container 700bd88a787b is using its referenced image e934aafc2206
[[email protected] docker_images]#
[[email protected] docker_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[[email protected] docker_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
700bd88a787b centos “/bin/bash” 19 hours ago Exited (0) 19 hours ago lonely_dubinsky
[[email protected] docker_images]# docker rm 70
70
[[email protected] docker_images]# docker rmi centos
Untagged: centos:latest
Deleted: sha256:e934aafc22064b7322c0250f1e32e5ce93b2d19b356f4537f5864bd102e8531f
Deleted: sha256:43e653f84b79ba52711b0f726ff5a7fd1162ae9df4be76ca1de8370b8bbf9bb0
可以看到,现在干净了,什么都没有了
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 2 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 5 months ago 79.62 MB
registry latest d1fd7d86a825 9 months ago 33.26 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB

如果没有镜像,直接运行,docker会去仓库去下载
[[email protected] docker_images]# docker run -it centos
Unable to find image ‘centos:latest’ locally
latest: Pulling from library/centos
aeb7866da422: Pull complete
Digest: sha256:67dad89757a55bfdfabec8abd0e22f8c7c12a1856514726470228063ed86593b
Status: Downloaded newer image for centos:latest
[[email protected] /]# exit
exit
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 75835a67d134 7 days ago 200.4 MB
busybox latest 59788edf1f3e 2 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 5 months ago 79.62 MB
registry latest d1fd7d86a825 9 months ago 33.26 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB

步骤二:容器命令

1)关闭容器
命令:docker stop 容器ID
[[email protected] docker_images]# docker stop 0f //0f为容器ID
0f
2)启动容器
[[email protected] docker_images]# docker start 0f
0f
3)重启容器
[[email protected] docker_images]# docker restart 0f
0f
4)删除容器
运行中删除不掉,先关闭容器
[[email protected] docker_images]# docker rm 0f //删除失败
Error response from daemon: You cannot remove a running container 0f63706692e15134a8f07655a992771b312b8eb01554fc37e1a39b03b28dd05c. Stop the container before attempting removal or use -f
[[email protected] docker_images]# docker stop 0f //关闭容器
0f
[[email protected] docker_images]# docker rm 0f //删除成功
0f
[[email protected] docker_images]#
5)连接容器attach|exec
[[email protected] docker_images]# docker attach 0f
[[email protected] docker_images]# docker ps //容器关闭
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[[email protected] docker_images]# docker exec -it 0f /bin/bash
[[email protected] docker_images]# docker ps //容器不会关闭
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0b3c50284a1c centos:v1 “/bin/bash” 15 minutes ago Up 15 minutes tiny_lamarr
[[email protected] docker_images]# docker top f7 //查看容器进程列表
[[email protected] ~]# docker run -itd centos:latest
[[email protected] /]# ps
PID TTY TIME CMD
1 ? 00:00:00 bash
13 ? 00:00:00 ps
[[email protected] docker_images]# docker exec -it 85 /bin/bash
[email protected]:/# sleep 50 &
[1] 9
[email protected]:/# exit
exit
[[email protected] docker_images]#docker top 85
UID PID PPID C STIME TTY TIME CMD
root 2744 2729 0 18:01 pts/4 00:00:00 /bin/bash
6)过滤查看mac和ip地址
[[email protected] docker_images]# docker inspect -f ‘{{.NetworkSettings.MacAddress}}’ 4f
02:42:ac:11:00:03
[[email protected] docker_images]# docker inspect -f ‘{{.NetworkSettings.IPAddress}}’ 4f
172.17.0.3
7)修改nginx的显示内容
[[email protected] docker_images]# docker run -it nginx:latest

[[email protected] docker_images]# docker exec -it 56 /bin/bash
[email protected]:/# nginx -T /usr/share/nginx/html/
nginx: invalid option: “/usr/share/nginx/html/” //查找并显示结果
[email protected]:/# echo aaa > /usr/share/nginx/html/index.html
//修改主页显示的内容
[email protected]:/# nginx -T
[email protected]:/# cat /usr/share/nginx/html/index.html
aaa
8)过滤查看nginx的ip地址
[[email protected] ~]# docker inspect -f ‘{{.NetworkSettings.IPAddress}}’ 56
172.17.0.5
[[email protected] ~]# curl 172.17.0.5
aaa

代码如下
查看容器
[[email protected] docker_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae3e9822ac24 centos “/bin/bash” 31 minutes ago Exited (127) 4 minutes ago big_almeida
关闭容器
[[email protected] docker_images]# docker stop ae
ae
[[email protected] docker_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[[email protected] docker_images]#
启动容器
[[email protected] docker_images]# docker start ae
ae
[[email protected] docker_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae3e9822ac24 centos “/bin/bash” 32 minutes ago Up 8 seconds big_almeida
重启容器
[[email protected] docker_images]# docker restart ae
ae
删除容器
[[email protected] docker_images]# docker stop ae
ae
[[email protected] docker_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae3e9822ac24 centos “/bin/bash” 35 minutes ago Exited (137) 5 seconds ago big_almeida
[[email protected] docker_images]# docker rm ae
ae
[[email protected] docker_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

连接容器 attach | exex
[[email protected] docker_images]# docker run -it centos
[[email protected] /]# ls
anaconda-post.log dev home lib64 mnt proc run srv tmp var
bin etc lib media opt root sbin sys usr
[[email protected] /]# exit
exit

退出后,启动容器,然后连接
[[email protected] docker_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cdfe1b4ffcca centos “/bin/bash” About a minute ago Exited (0) 40 seconds ago nauseous_dijkstra
[[email protected] docker_images]# docker attach cd
You cannot attach to a stopped container, start it first
[[email protected] docker_images]# docker start cd
cd
用attach连接
[[email protected] docker_images]# docker attach cd
[[email protected] /]# exit
exit
退出就没了
[[email protected] docker_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

用exec连接
[[email protected] docker_images]# docker start cd
cd
[[email protected] docker_images]# docker exec -it cd /bin/bash
[[email protected] /]# exit
exit
退出后容器不会关闭,这个就是区别
[[email protected] docker_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cdfe1b4ffcca centos “/bin/bash” 3 minutes ago Up 20 seconds nauseous_dijkstra

查看容器的进程列表,看清楚IDH号
[[email protected] docker_images]# docker top cd
UID PID PPID C STIME TTY TIME CMD
root 12570 12556 0 11:45 pts/1 00:00:00 /bin/bash
[[email protected] docker_images]# docker run -itd centos:latest
3b0d94d4bacdd169013410b0734ef20b876bced7d8fea4137618e4f45f6af82c
[[email protected] docker_images]# ps
PID TTY TIME CMD
802 pts/0 00:00:00 bash
12725 pts/0 00:00:00 ps
[[email protected] docker_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b0d94d4bacd centos:latest “/bin/bash” 55 seconds ago Up 52 seconds silly_pasteur
cdfe1b4ffcca centos “/bin/bash” 7 minutes ago Up 3 minutes nauseous_dijkstra
[[email protected] docker_images]# docker exec -it 3b /bin/bash
[[email protected] /]# sleep 50&
[1] 25
[[email protected] /]# exit
exit
[[email protected] docker_images]# docker top 3b
UID PID PPID C STIME TTY TIME CMD
root 12702 12688 0 11:47 pts/2 00:00:00 /bin/bash

查看MAC和IP地址
[[email protected] docker_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b0d94d4bacd centos:latest “/bin/bash” 4 minutes ago Up 4 minutes silly_pasteur
cdfe1b4ffcca centos “/bin/bash” 10 minutes ago Up 6 minutes nauseous_dijkstra
[[email protected] docker_images]# docker inspect -f ‘{{.NetworkSettings.MacAddress}}’ 3b
02:42:ac:11:00:03
[[email protected] docker_images]# docker inspect -f ‘{{.NetworkSettings.MacAddress}}’ cd
02:42:ac:11:00:02
[[email protected] docker_images]# docker inspect -f ‘{{.NetworkSettings.IPAddress}}’ 3b
172.17.0.3
[[email protected] docker_images]# docker inspect -f ‘{{.NetworkSettings.IPAddress}}’ cd
172.17.0.2
[[email protected] docker_images]#

修改nginx的显示内容
[[email protected] docker_images]# docker run -it nginx:latest
Unable to find image ‘nginx:latest’ locally
latest: Pulling from library/nginx

f17d81b4b692: Pull complete
d5c237920c39: Pull complete
a381f92f36de: Pull complete
Digest: sha256:b73f527d86e3461fd652f62cf47e7b375196063bbbd503e853af5be16597cb2e
Status: Downloaded newer image for nginx:latest
[[email protected] docker_images]#

[[email protected] docker_images]# docker start 3b
Error response from daemon: Multiple IDs found with provided prefix: 3b89902c3001651dae3e3bf1d8a0667d530d9854f55a1a4de87aed0844776a4d
Error: failed to start containers: 3b
[[email protected] docker_images]# docker start 3b8
3b8
[[email protected] docker_images]# docker exec -it 3b8 /bin/bash
[email protected]:/# nginx -T /usr/share/nginx/html/
nginx: invalid option: “/usr/share/nginx/html/”
[email protected]:/# echo aaa > /usr/share/nginx/html/index.html
[email protected]:/# nginx -T
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}

# configuration file /etc/nginx/mime.types:

types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;

text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;

image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;

font/woff woff;
font/woff2 woff2;

application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;

application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;

audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;

video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}

# configuration file /etc/nginx/conf.d/default.conf:
server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#}
}

[email protected]:/# nginx -T /usr/share/nginx/html/
nginx: invalid option: “/usr/share/nginx/html/”
[email protected]:/# nginx -T /usr/share/nginx/html/
50x.html index.html
[email protected]:/# nginx -T /usr/share/nginx/html/index.html
nginx: invalid option: “/usr/share/nginx/html/index.html”
[email protected]:/# cat /usr/share/nginx/html/index.html
aaa

8)过滤查看nginx的ip地址
测试确认一下
[[email protected] docker_images]# docker inspect -f ‘{{.NetworkSettings.IPAddress}}’ 3b8
172.17.0.4
[[email protected] docker_images]# curl 172.17.0.4
aaa

此条目发表在Docker分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注