Docker02-Docker简单使用

1 案例1:制作自定义镜像
1.1 问题

本案例要求制作自定义镜像:
基于centos镜像使用commit创建新的镜像文件
基于centos镜像使用Dockerfile文件创建一个新的镜像文件
1.2 步骤

实现此案例需要按照如下步骤进行。
步骤一:使用镜像启动容器

1)在该容器基础上修改yum源
[[email protected] docker_images]# docker run -it centos
[[email protected] /]# rm -rf /etc/yum.repos.d/*
[[email protected] /]# vi /etc/yum.repos.d/dvd.repo
[dvd]
name=dvd
baseurl=ftp://192.168.1.254/system
enabled=1
gpgcheck=0
[[email protected] /]# yum clean all
[[email protected] /]# yum repolist
2)安装测试软件
[[email protected] /]# yum -y install net-tools iproute psmisc vim-enhanced
3)ifconfig查看
[[email protected] /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.3 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:3 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)
RX packets 2488 bytes 28317945 (27.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1858 bytes 130264 (127.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[[email protected] /]# exit
exit

代码如下
[[email protected] docker_images]# docker run -it centos
[[email protected] /]# rm -rf /etc/yum.repos.d/*
[[email protected] /]# vi /etc/yum.repos.d/dvd.repo
[[email protected] /]# yum clean all
Loaded plugins: fastestmirror, ovl
Cleaning repos: dvd
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
[[email protected] /]# yum repolist
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
dvd | 3.6 kB 00:00:00
(1/2): dvd/group_gz | 156 kB 00:00:00
(2/2): dvd/primary_db | 5.7 MB 00:00:00
repo id repo name status
dvd dvd 9591
repolist: 9591
[[email protected] /]# yum -y install net-tools iproute psmisc vim-enhanced
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
Resolving Dependencies
–> Running transaction check
—> Package iproute.x86_64 0:3.10.0-87.el7 will be installed
–> Processing Dependency: libmnl.so.0(LIBMNL_1.0)(64bit) for package: iproute-3.10.0-87.el7.x86_64
–> Processing Dependency: libxtables.so.10()(64bit) for package: iproute-3.10.0-87.el7.x86_64
–> Processing Dependency: libmnl.so.0()(64bit) for package: iproute-3.10.0-87.el7.x86_64
—> Package net-tools.x86_64 0:2.0-0.22.20131004git.el7 will be installed
—> Package psmisc.x86_64 0:22.20-15.el7 will be installed
—> Package vim-enhanced.x86_64 2:7.4.160-2.el7 will be installed
–> Processing Dependency: vim-common = 2:7.4.160-2.el7 for package: 2:vim-enhanced-7.4.160-2.el7.x86_64
–> Processing Dependency: which for package: 2:vim-enhanced-7.4.160-2.el7.x86_64
–> Processing Dependency: perl(:MODULE_COMPAT_5.16.3) for package: 2:vim-enhanced-7.4.160-2.el7.x86_64
–> Processing Dependency: libperl.so()(64bit) for package: 2:vim-enhanced-7.4.160-2.el7.x86_64
–> Processing Dependency: libgpm.so.2()(64bit) for package: 2:vim-enhanced-7.4.160-2.el7.x86_64
–> Running transaction check
—> Package gpm-libs.x86_64 0:1.20.7-5.el7 will be installed
—> Package iptables.x86_64 0:1.4.21-18.0.1.el7.centos will be installed
–> Processing Dependency: libnfnetlink.so.0()(64bit) for package: iptables-1.4.21-18.0.1.el7.centos.x86_64
–> Processing Dependency: libnetfilter_conntrack.so.3()(64bit) for package: iptables-1.4.21-18.0.1.el7.centos.x86_64
—> Package libmnl.x86_64 0:1.0.3-7.el7 will be installed
—> Package perl.x86_64 4:5.16.3-292.el7 will be installed
–> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl-macros for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(threads::shared) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(threads) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(constant) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Time::Local) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Time::HiRes) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Storable) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Socket) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Scalar::Util) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Pod::Simple::XHTML) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Pod::Simple::Search) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Getopt::Long) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Filter::Util::Call) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(File::Temp) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(File::Spec::Unix) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(File::Spec::Functions) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(File::Spec) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(File::Path) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Exporter) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Cwd) for package: 4:perl-5.16.3-292.el7.x86_64
–> Processing Dependency: perl(Carp) for package: 4:perl-5.16.3-292.el7.x86_64
—> Package perl-libs.x86_64 4:5.16.3-292.el7 will be installed
—> Package vim-common.x86_64 2:7.4.160-2.el7 will be installed
–> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.160-2.el7.x86_64
—> Package which.x86_64 0:2.20-7.el7 will be installed
–> Running transaction check
—> Package libnetfilter_conntrack.x86_64 0:1.0.6-1.el7_3 will be installed
—> Package libnfnetlink.x86_64 0:1.0.1-4.el7 will be installed
—> Package perl-Carp.noarch 0:1.26-244.el7 will be installed
—> Package perl-Exporter.noarch 0:5.68-3.el7 will be installed
—> Package perl-File-Path.noarch 0:2.09-2.el7 will be installed
—> Package perl-File-Temp.noarch 0:0.23.01-3.el7 will be installed
—> Package perl-Filter.x86_64 0:1.49-3.el7 will be installed
—> Package perl-Getopt-Long.noarch 0:2.40-2.el7 will be installed
–> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-2.el7.noarch
–> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-2.el7.noarch
—> Package perl-PathTools.x86_64 0:3.40-5.el7 will be installed
—> Package perl-Pod-Simple.noarch 1:3.28-4.el7 will be installed
–> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
–> Processing Dependency: perl(Encode) for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
—> Package perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 will be installed
—> Package perl-Socket.x86_64 0:2.010-4.el7 will be installed
—> Package perl-Storable.x86_64 0:2.45-3.el7 will be installed
—> Package perl-Time-HiRes.x86_64 4:1.9725-3.el7 will be installed
—> Package perl-Time-Local.noarch 0:1.2300-2.el7 will be installed
—> Package perl-constant.noarch 0:1.27-2.el7 will be installed
—> Package perl-macros.x86_64 4:5.16.3-292.el7 will be installed
—> Package perl-threads.x86_64 0:1.87-4.el7 will be installed
—> Package perl-threads-shared.x86_64 0:1.43-6.el7 will be installed
—> Package vim-filesystem.x86_64 2:7.4.160-2.el7 will be installed
–> Running transaction check
—> Package perl-Encode.x86_64 0:2.51-7.el7 will be installed
—> Package perl-Pod-Escapes.noarch 1:1.04-292.el7 will be installed
—> Package perl-Pod-Usage.noarch 0:1.63-3.el7 will be installed
–> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-3.el7.noarch
–> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-3.el7.noarch
—> Package perl-Text-ParseWords.noarch 0:3.29-4.el7 will be installed
–> Running transaction check
—> Package perl-Pod-Perldoc.noarch 0:3.20-4.el7 will be installed
–> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
–> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
–> Processing Dependency: groff-base for package: perl-Pod-Perldoc-3.20-4.el7.noarch
—> Package perl-podlators.noarch 0:2.5.1-3.el7 will be installed
–> Running transaction check
—> Package groff-base.x86_64 0:1.22.2-8.el7 will be installed
—> Package perl-HTTP-Tiny.noarch 0:0.033-3.el7 will be installed
—> Package perl-parent.noarch 1:0.225-244.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
Package Arch Version Repository
Size
=============================================================================================
Installing:
iproute x86_64 3.10.0-87.el7 dvd 651 k
net-tools x86_64 2.0-0.22.20131004git.el7 dvd 305 k
psmisc x86_64 22.20-15.el7 dvd 141 k
vim-enhanced x86_64 2:7.4.160-2.el7 dvd 1.0 M
Installing for dependencies:
gpm-libs x86_64 1.20.7-5.el7 dvd 32 k
groff-base x86_64 1.22.2-8.el7 dvd 942 k
iptables x86_64 1.4.21-18.0.1.el7.centos dvd 428 k
libmnl x86_64 1.0.3-7.el7 dvd 23 k
libnetfilter_conntrack x86_64 1.0.6-1.el7_3 dvd 55 k
libnfnetlink x86_64 1.0.1-4.el7 dvd 26 k
perl x86_64 4:5.16.3-292.el7 dvd 8.0 M
perl-Carp noarch 1.26-244.el7 dvd 19 k
perl-Encode x86_64 2.51-7.el7 dvd 1.5 M
perl-Exporter noarch 5.68-3.el7 dvd 28 k
perl-File-Path noarch 2.09-2.el7 dvd 26 k
perl-File-Temp noarch 0.23.01-3.el7 dvd 56 k
perl-Filter x86_64 1.49-3.el7 dvd 76 k
perl-Getopt-Long noarch 2.40-2.el7 dvd 56 k
perl-HTTP-Tiny noarch 0.033-3.el7 dvd 38 k
perl-PathTools x86_64 3.40-5.el7 dvd 82 k
perl-Pod-Escapes noarch 1:1.04-292.el7 dvd 51 k
perl-Pod-Perldoc noarch 3.20-4.el7 dvd 87 k
perl-Pod-Simple noarch 1:3.28-4.el7 dvd 216 k
perl-Pod-Usage noarch 1.63-3.el7 dvd 27 k
perl-Scalar-List-Utils x86_64 1.27-248.el7 dvd 36 k
perl-Socket x86_64 2.010-4.el7 dvd 49 k
perl-Storable x86_64 2.45-3.el7 dvd 77 k
perl-Text-ParseWords noarch 3.29-4.el7 dvd 14 k
perl-Time-HiRes x86_64 4:1.9725-3.el7 dvd 45 k
perl-Time-Local noarch 1.2300-2.el7 dvd 24 k
perl-constant noarch 1.27-2.el7 dvd 19 k
perl-libs x86_64 4:5.16.3-292.el7 dvd 688 k
perl-macros x86_64 4:5.16.3-292.el7 dvd 43 k
perl-parent noarch 1:0.225-244.el7 dvd 12 k
perl-podlators noarch 2.5.1-3.el7 dvd 112 k
perl-threads x86_64 1.87-4.el7 dvd 49 k
perl-threads-shared x86_64 1.43-6.el7 dvd 39 k
vim-common x86_64 2:7.4.160-2.el7 dvd 5.9 M
vim-filesystem x86_64 2:7.4.160-2.el7 dvd 9.8 k
which x86_64 2.20-7.el7 dvd 41 k

Transaction Summary
=============================================================================================
Install 4 Packages (+36 Dependent packages)

Total download size: 21 M
Installed size: 67 M
Downloading packages:
(1/40): gpm-libs-1.20.7-5.el7.x86_64.rpm | 32 kB 00:00:00
(2/40): groff-base-1.22.2-8.el7.x86_64.rpm | 942 kB 00:00:00
(3/40): iproute-3.10.0-87.el7.x86_64.rpm | 651 kB 00:00:00
(4/40): libmnl-1.0.3-7.el7.x86_64.rpm | 23 kB 00:00:00
(5/40): iptables-1.4.21-18.0.1.el7.centos.x86_64.rpm | 428 kB 00:00:00
(6/40): libnetfilter_conntrack-1.0.6-1.el7_3.x86_64.rpm | 55 kB 00:00:00
(7/40): libnfnetlink-1.0.1-4.el7.x86_64.rpm | 26 kB 00:00:00
(8/40): net-tools-2.0-0.22.20131004git.el7.x86_64.rpm | 305 kB 00:00:00
(9/40): perl-Carp-1.26-244.el7.noarch.rpm | 19 kB 00:00:00
(10/40): perl-Encode-2.51-7.el7.x86_64.rpm | 1.5 MB 00:00:00
(11/40): perl-Exporter-5.68-3.el7.noarch.rpm | 28 kB 00:00:00
(12/40): perl-File-Path-2.09-2.el7.noarch.rpm | 26 kB 00:00:00
(13/40): perl-File-Temp-0.23.01-3.el7.noarch.rpm | 56 kB 00:00:00
(14/40): perl-Filter-1.49-3.el7.x86_64.rpm | 76 kB 00:00:00
(15/40): perl-Getopt-Long-2.40-2.el7.noarch.rpm | 56 kB 00:00:00
(16/40): perl-5.16.3-292.el7.x86_64.rpm | 8.0 MB 00:00:00
(17/40): perl-HTTP-Tiny-0.033-3.el7.noarch.rpm | 38 kB 00:00:00
(18/40): perl-PathTools-3.40-5.el7.x86_64.rpm | 82 kB 00:00:00
(19/40): perl-Pod-Escapes-1.04-292.el7.noarch.rpm | 51 kB 00:00:00
(20/40): perl-Pod-Perldoc-3.20-4.el7.noarch.rpm | 87 kB 00:00:00
(21/40): perl-Pod-Simple-3.28-4.el7.noarch.rpm | 216 kB 00:00:00
(22/40): perl-Pod-Usage-1.63-3.el7.noarch.rpm | 27 kB 00:00:00
(23/40): perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm | 36 kB 00:00:00
(24/40): perl-Socket-2.010-4.el7.x86_64.rpm | 49 kB 00:00:00
(25/40): perl-Storable-2.45-3.el7.x86_64.rpm | 77 kB 00:00:00
(26/40): perl-Text-ParseWords-3.29-4.el7.noarch.rpm | 14 kB 00:00:00
(27/40): perl-Time-HiRes-1.9725-3.el7.x86_64.rpm | 45 kB 00:00:00
(28/40): perl-Time-Local-1.2300-2.el7.noarch.rpm | 24 kB 00:00:00
(29/40): perl-constant-1.27-2.el7.noarch.rpm | 19 kB 00:00:00
(30/40): perl-macros-5.16.3-292.el7.x86_64.rpm | 43 kB 00:00:00
(31/40): perl-libs-5.16.3-292.el7.x86_64.rpm | 688 kB 00:00:00
(32/40): perl-parent-0.225-244.el7.noarch.rpm | 12 kB 00:00:00
(33/40): perl-podlators-2.5.1-3.el7.noarch.rpm | 112 kB 00:00:00
(34/40): perl-threads-1.87-4.el7.x86_64.rpm | 49 kB 00:00:00
(35/40): perl-threads-shared-1.43-6.el7.x86_64.rpm | 39 kB 00:00:00
(36/40): psmisc-22.20-15.el7.x86_64.rpm | 141 kB 00:00:00
(37/40): vim-enhanced-7.4.160-2.el7.x86_64.rpm | 1.0 MB 00:00:00
(38/40): vim-filesystem-7.4.160-2.el7.x86_64.rpm | 9.8 kB 00:00:00
(39/40): vim-common-7.4.160-2.el7.x86_64.rpm | 5.9 MB 00:00:00
(40/40): which-2.20-7.el7.x86_64.rpm | 41 kB 00:00:00
———————————————————————————————
Total 21 MB/s | 21 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libnfnetlink-1.0.1-4.el7.x86_64 1/40
Installing : libmnl-1.0.3-7.el7.x86_64 2/40
Installing : libnetfilter_conntrack-1.0.6-1.el7_3.x86_64 3/40
Installing : iptables-1.4.21-18.0.1.el7.centos.x86_64 4/40
Installing : gpm-libs-1.20.7-5.el7.x86_64 5/40
Installing : groff-base-1.22.2-8.el7.x86_64 6/40
Installing : 1:perl-parent-0.225-244.el7.noarch 7/40
Installing : perl-HTTP-Tiny-0.033-3.el7.noarch 8/40
Installing : perl-podlators-2.5.1-3.el7.noarch 9/40
Installing : perl-Pod-Perldoc-3.20-4.el7.noarch 10/40
Installing : 1:perl-Pod-Escapes-1.04-292.el7.noarch 11/40
Installing : perl-Text-ParseWords-3.29-4.el7.noarch 12/40
Installing : perl-Encode-2.51-7.el7.x86_64 13/40
Installing : perl-Pod-Usage-1.63-3.el7.noarch 14/40
Installing : 4:perl-macros-5.16.3-292.el7.x86_64 15/40
Installing : 4:perl-libs-5.16.3-292.el7.x86_64 16/40
Installing : perl-Storable-2.45-3.el7.x86_64 17/40
Installing : perl-Exporter-5.68-3.el7.noarch 18/40
Installing : perl-constant-1.27-2.el7.noarch 19/40
Installing : perl-Time-Local-1.2300-2.el7.noarch 20/40
Installing : perl-Socket-2.010-4.el7.x86_64 21/40
Installing : perl-Carp-1.26-244.el7.noarch 22/40
Installing : perl-PathTools-3.40-5.el7.x86_64 23/40
Installing : perl-Scalar-List-Utils-1.27-248.el7.x86_64 24/40
Installing : perl-File-Temp-0.23.01-3.el7.noarch 25/40
Installing : perl-File-Path-2.09-2.el7.noarch 26/40
Installing : perl-threads-shared-1.43-6.el7.x86_64 27/40
Installing : perl-threads-1.87-4.el7.x86_64 28/40
Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 29/40
Installing : perl-Filter-1.49-3.el7.x86_64 30/40
Installing : 1:perl-Pod-Simple-3.28-4.el7.noarch 31/40
Installing : perl-Getopt-Long-2.40-2.el7.noarch 32/40
Installing : 4:perl-5.16.3-292.el7.x86_64 33/40
Installing : which-2.20-7.el7.x86_64 34/40
install-info: No such file or directory for /usr/share/info/which.info.gz
Installing : 2:vim-filesystem-7.4.160-2.el7.x86_64 35/40
Installing : 2:vim-common-7.4.160-2.el7.x86_64 36/40
Installing : 2:vim-enhanced-7.4.160-2.el7.x86_64 37/40
Installing : iproute-3.10.0-87.el7.x86_64 38/40
Installing : psmisc-22.20-15.el7.x86_64 39/40
Installing : net-tools-2.0-0.22.20131004git.el7.x86_64 40/40
Verifying : perl-HTTP-Tiny-0.033-3.el7.noarch 1/40
Verifying : libmnl-1.0.3-7.el7.x86_64 2/40
Verifying : net-tools-2.0-0.22.20131004git.el7.x86_64 3/40
Verifying : perl-threads-shared-1.43-6.el7.x86_64 4/40
Verifying : perl-Storable-2.45-3.el7.x86_64 5/40
Verifying : 2:vim-filesystem-7.4.160-2.el7.x86_64 6/40
Verifying : perl-Exporter-5.68-3.el7.noarch 7/40
Verifying : perl-constant-1.27-2.el7.noarch 8/40
Verifying : perl-PathTools-3.40-5.el7.x86_64 9/40
Verifying : libnetfilter_conntrack-1.0.6-1.el7_3.x86_64 10/40
Verifying : 4:perl-macros-5.16.3-292.el7.x86_64 11/40
Verifying : 1:perl-parent-0.225-244.el7.noarch 12/40
Verifying : 4:perl-5.16.3-292.el7.x86_64 13/40
Verifying : iproute-3.10.0-87.el7.x86_64 14/40
Verifying : which-2.20-7.el7.x86_64 15/40
Verifying : groff-base-1.22.2-8.el7.x86_64 16/40
Verifying : perl-File-Temp-0.23.01-3.el7.noarch 17/40
Verifying : 1:perl-Pod-Simple-3.28-4.el7.noarch 18/40
Verifying : perl-Time-Local-1.2300-2.el7.noarch 19/40
Verifying : gpm-libs-1.20.7-5.el7.x86_64 20/40
Verifying : 4:perl-libs-5.16.3-292.el7.x86_64 21/40
Verifying : psmisc-22.20-15.el7.x86_64 22/40
Verifying : perl-Socket-2.010-4.el7.x86_64 23/40
Verifying : perl-Carp-1.26-244.el7.noarch 24/40
Verifying : 2:vim-common-7.4.160-2.el7.x86_64 25/40
Verifying : perl-Scalar-List-Utils-1.27-248.el7.x86_64 26/40
Verifying : 1:perl-Pod-Escapes-1.04-292.el7.noarch 27/40
Verifying : perl-Pod-Usage-1.63-3.el7.noarch 28/40
Verifying : perl-Encode-2.51-7.el7.x86_64 29/40
Verifying : libnfnetlink-1.0.1-4.el7.x86_64 30/40
Verifying : perl-podlators-2.5.1-3.el7.noarch 31/40
Verifying : perl-Getopt-Long-2.40-2.el7.noarch 32/40
Verifying : 2:vim-enhanced-7.4.160-2.el7.x86_64 33/40
Verifying : perl-File-Path-2.09-2.el7.noarch 34/40
Verifying : perl-threads-1.87-4.el7.x86_64 35/40
Verifying : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 36/40
Verifying : perl-Filter-1.49-3.el7.x86_64 37/40
Verifying : perl-Pod-Perldoc-3.20-4.el7.noarch 38/40
Verifying : perl-Text-ParseWords-3.29-4.el7.noarch 39/40
Verifying : iptables-1.4.21-18.0.1.el7.centos.x86_64 40/40

Installed:
iproute.x86_64 0:3.10.0-87.el7 net-tools.x86_64 0:2.0-0.22.20131004git.el7
psmisc.x86_64 0:22.20-15.el7 vim-enhanced.x86_64 2:7.4.160-2.el7

Dependency Installed:
gpm-libs.x86_64 0:1.20.7-5.el7 groff-base.x86_64 0:1.22.2-8.el7
iptables.x86_64 0:1.4.21-18.0.1.el7.centos libmnl.x86_64 0:1.0.3-7.el7
libnetfilter_conntrack.x86_64 0:1.0.6-1.el7_3 libnfnetlink.x86_64 0:1.0.1-4.el7
perl.x86_64 4:5.16.3-292.el7 perl-Carp.noarch 0:1.26-244.el7
perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7
perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7
perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-2.el7
perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-PathTools.x86_64 0:3.40-5.el7
perl-Pod-Escapes.noarch 1:1.04-292.el7 perl-Pod-Perldoc.noarch 0:3.20-4.el7
perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7
perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7
perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7
perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7
perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-292.el7
perl-macros.x86_64 4:5.16.3-292.el7 perl-parent.noarch 1:0.225-244.el7
perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7
perl-threads-shared.x86_64 0:1.43-6.el7 vim-common.x86_64 2:7.4.160-2.el7
vim-filesystem.x86_64 2:7.4.160-2.el7 which.x86_64 0:2.20-7.el7

Complete!
[[email protected] /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.5 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:5 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:05 txqueuelen 0 (Ethernet)
RX packets 1806 bytes 28258678 (26.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1465 bytes 103699 (101.2 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] /]# exit
exit

步骤二:另存为另外一个镜像

1)创建新建镜像
[[email protected] docker_images]# docker start 8d07ecd7e345
//可以简写为8d,要保证唯一性
8d07ecd7e345
[[email protected] docker_images]# docker commit 8d07ecd7e345 myos:v1
sha256:ac3f9c2e8c7e13db183636821783f997890029d687b694f5ce590a473ad82c5f

3)验证新建镜像
[[email protected] docker_images]# docker run -it myos:v1
[[email protected] /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.6 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:6 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:06 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7 bytes 578 (578.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

代码如下
先回放一下,那个2f才是我们要操作的镜像
[[email protected] docker_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2f357316ddca centos “/bin/bash” About an hour ago Exited (0) 5 minutes ago loving_bartik
3b89902c3001 nginx:latest “nginx -g ‘daemon off” 5 hours ago Up About an hour 80/tcp desperate_borg
3b0d94d4bacd centos:latest “/bin/bash” 5 hours ago Up 5 hours silly_pasteur
cdfe1b4ffcca centos “/bin/bash” 5 hours ago Up 5 hours nauseous_dijkstra
另存为一下镜像
[[email protected] docker_images]# docker start 2f
2f
[[email protected] docker_images]# docker commit 2f357316ddca myos:v1
sha256:c698fb4a59102b1068fa35e2db6822ace643a2e83318268bb877a71015206fca
[[email protected] docker_images]#
确认一下,这个myos就是我们刚才创建的镜像
[[email protected] docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myos v1 c698fb4a5910 43 seconds ago 317.7 MB
nginx latest dbfc48660aeb 27 hours ago 109.1 MB
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
然后验证一下,用这个镜像,启动一个容器
[[email protected] docker_images]# docker run -it myos:v1
[[email protected] /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.6 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:6 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:06 txqueuelen 0 (Ethernet)
RX packets 6 bytes 508 (508.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6 bytes 508 (508.0 B)
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] /]# exit
exit
别搞晕了,注意看那个IMAGE的内容
[[email protected] docker_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
029680fbd1b3 myos:v1 “/bin/bash” 44 seconds ago Exited (0) 32 seconds ago determined_einstein
2f357316ddca centos “/bin/bash” About an hour ago Up 3 minutes loving_bartik
3b89902c3001 nginx:latest “nginx -g ‘daemon off” 5 hours ago Up About an hour 80/tcp desperate_borg
3b0d94d4bacd centos:latest “/bin/bash” 5 hours ago Up 5 hours silly_pasteur
cdfe1b4ffcca centos “/bin/bash” 5 hours ago Up 5 hours nauseous_dijkstra

步骤三:使用Dockerfile文件创建一个新的镜像文件

Dockerfile语法格式:
– FROM:基础镜像
– MAINTAINER:镜像创建者信息(说明)
– EXPOSE:开放的端口
– ENV:设置环境变量
– ADD:复制文件到镜像
– RUN:制作镜像时执行的命令,可以有多个
– WORKDIR:定义容器默认工作目录
– CMD:容器启动时执行的命令,仅可以有一条CMD
1)创建一个Apache的镜像文件
[[email protected] ~]# mkdir oo
[[email protected] ~]# cd oo
[[email protected] oo]# touch Dockerfile //Dockerfile文件第一个字母要大写
[[email protected] oo]# cp /etc/yum.repos.d/local.repo ./
[[email protected] oo]# vi Dockerfile
FROM myos:v1
RUN yum -y install httpd
ENV EnvironmentFile=/etc/sysconfig/httpd
WORKDIR /var/www/html/ //定义容器默认工作目录
RUN echo “test” > /var/www/html/index.html
EXPOSE 80 //设置开放端口号
CMD [“/usr/sbin/httpd”, “-DFOREGROUND”]
[[email protected] oo]# docker build -t myos:http .
[[email protected] oo]# docker run -d myos:http
d9a5402709b26b42cd304c77be442559a5329dc784ec4f6c90e4abac1c88e206
[[email protected] oo]# docker inspect d9
[[email protected] oo]# curl 172.17.0.7
test
代码如下
创建文件夹并写好脚本
[[email protected] ~]# mkdir oo
[[email protected] ~]# cd oo
[[email protected] oo]# touch Dockerfile
[[email protected] oo]# cp /etc/yum.repos.d/local.repo ./
[[email protected] oo]# ls
Dockerfile local.repo
[[email protected] oo]# vim Dockerfile
[[email protected] oo]#
[[email protected] oo]# cat Dockerfile
FROM myos:v1
RUN yum -y install httpd
ENV EnvironmentFile=/etc/sysconfig/httpd
WORKDIR /var/www/html/
RUN echo “test” > /var/www/html/index.html
EXPOSE 80
CMD [“/usr/sbin/httpd”, “-DFOREGROUND”]

开始创建镜像
[[email protected] oo]# docker build -t myos:http .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM myos:v1
—> c698fb4a5910
Step 2 : RUN yum -y install httpd
—> Running in d9cb6e5bc8b4
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.4.6-67.el7.centos will be installed
–> Processing Dependency: httpd-tools = 2.4.6-67.el7.centos for package: httpd-2.4.6-67.el7.centos.x86_64
–> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-67.el7.centos.x86_64
–> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-67.el7.centos.x86_64
–> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.x86_64
–> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.x86_64
–> Running transaction check
—> Package apr.x86_64 0:1.4.8-3.el7 will be installed
—> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
—> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
—> Package httpd-tools.x86_64 0:2.4.6-67.el7.centos will be installed
—> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.6-67.el7.centos dvd 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 dvd 103 k
apr-util x86_64 1.5.2-6.el7 dvd 92 k
centos-logos noarch 70.0.6-3.el7.centos dvd 21 M
httpd-tools x86_64 2.4.6-67.el7.centos dvd 87 k
mailcap noarch 2.1.41-2.el7 dvd 31 k

Transaction Summary
================================================================================
Install 1 Package (+5 Dependent packages)

Total download size: 24 M
Installed size: 32 M
Downloading packages:
——————————————————————————–
Total 44 MB/s | 24 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/6
Installing : apr-util-1.5.2-6.el7.x86_64 2/6
Installing : httpd-tools-2.4.6-67.el7.centos.x86_64 3/6
Installing : centos-logos-70.0.6-3.el7.centos.noarch 4/6
Installing : mailcap-2.1.41-2.el7.noarch 5/6
Installing : httpd-2.4.6-67.el7.centos.x86_64 6/6
Verifying : apr-1.4.8-3.el7.x86_64 1/6
Verifying : httpd-2.4.6-67.el7.centos.x86_64 2/6
Verifying : mailcap-2.1.41-2.el7.noarch 3/6
Verifying : httpd-tools-2.4.6-67.el7.centos.x86_64 4/6
Verifying : apr-util-1.5.2-6.el7.x86_64 5/6
Verifying : centos-logos-70.0.6-3.el7.centos.noarch 6/6

Installed:
httpd.x86_64 0:2.4.6-67.el7.centos

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7
apr-util.x86_64 0:1.5.2-6.el7
centos-logos.noarch 0:70.0.6-3.el7.centos
httpd-tools.x86_64 0:2.4.6-67.el7.centos
mailcap.noarch 0:2.1.41-2.el7

Complete!
—> 30bb477046d6
Removing intermediate container d9cb6e5bc8b4
Step 3 : ENV EnvironmentFile /etc/sysconfig/httpd
—> Running in ef6e27bf5193
—> d25198228cb8
Removing intermediate container ef6e27bf5193
Step 4 : WORKDIR /var/www/html/
—> Running in 4e3789dea966
—> 0895ae11d5c3
Removing intermediate container 4e3789dea966
Step 5 : RUN echo “test” > /var/www/html/index.html
—> Running in b718560ff97b
—> 0f42aa31bc01
Removing intermediate container b718560ff97b
Step 6 : EXPOSE 80
—> Running in 87ccc22b5dc3
—> 5ebc4c2a949f
Removing intermediate container 87ccc22b5dc3
Step 7 : CMD /usr/sbin/httpd -DFOREGROUND
—> Running in 60817d264dd4
—> 5edae862ee2e
Removing intermediate container 60817d264dd4
Successfully built 5edae862ee2e

确认一下镜像,这个5e就是我们刚才创建的镜像
[[email protected] oo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myos http 5edae862ee2e 25 seconds ago 373 MB
myos v1 c698fb4a5910 20 hours ago 317.7 MB
nginx latest dbfc48660aeb 2 days ago 109.1 MB
centos latest 75835a67d134 8 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

就用刚才创建的镜像启动一个容器,查一下IP,然后访问一下试试看
[[email protected] oo]# docker run -d myos:http
0471288b2f917b2b8b3daa1591fcda60345802b3b74fe94095e6f922075e615c
[[email protected] oo]# docker inspect 04
[
{
“Id”: “0471288b2f917b2b8b3daa1591fcda60345802b3b74fe94095e6f922075e615c”,
“Created”: “2018-10-18T06:27:47.825416388Z”,
“Path”: “/usr/sbin/httpd”,
“Args”: [
“-DFOREGROUND”
],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 1809,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2018-10-18T06:27:50.298713344Z”,
“FinishedAt”: “0001-01-01T00:00:00Z”
},
“Image”: “sha256:5edae862ee2e7b7fec4459ac1c61628f94245afd507924b03a49a6d9c7d53972”,
“ResolvConfPath”: “/var/lib/docker/containers/0471288b2f917b2b8b3daa1591fcda60345802b3b74fe94095e6f922075e615c/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/0471288b2f917b2b8b3daa1591fcda60345802b3b74fe94095e6f922075e615c/hostname”,
“HostsPath”: “/var/lib/docker/containers/0471288b2f917b2b8b3daa1591fcda60345802b3b74fe94095e6f922075e615c/hosts”,
“LogPath”: “/var/lib/docker/containers/0471288b2f917b2b8b3daa1591fcda60345802b3b74fe94095e6f922075e615c/0471288b2f917b2b8b3daa1591fcda60345802b3b74fe94095e6f922075e615c-json.log”,
“Name”: “/romantic_keller”,
“RestartCount”: 0,
“Driver”: “devicemapper”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: null,
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “default”,
“PortBindings”: {},
“RestartPolicy”: {
“Name”: “no”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: null,
“CapAdd”: null,
“CapDrop”: null,
“Dns”: [],
“DnsOptions”: [],
“DnsSearch”: [],
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
0,
0
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: null,
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: [],
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: -1,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0
},
“GraphDriver”: {
“Name”: “devicemapper”,
“Data”: {
“DeviceId”: “54”,
“DeviceName”: “docker-253:1-8388784-7037d86754d1db7a5ea60253acdac8720a1bc7c863038a108f6364bc6c5a9ef6”,
“DeviceSize”: “10737418240”
}
},
“Mounts”: [],
“Config”: {
“Hostname”: “0471288b2f91”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“80/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
“EnvironmentFile=/etc/sysconfig/httpd”
],
“Cmd”: [
“/usr/sbin/httpd”,
“-DFOREGROUND”
],
“Image”: “myos:http”,
“Volumes”: null,
“WorkingDir”: “/var/www/html”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {
“org.label-schema.build-date”: “20181006”,
“org.label-schema.license”: “GPLv2”,
“org.label-schema.name”: “CentOS Base Image”,
“org.label-schema.schema-version”: “1.0”,
“org.label-schema.vendor”: “CentOS”
}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “4ee191b3751a70e318101433c293548c7594e999ae1ca21682547bf066f8271b”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {
“80/tcp”: null
},
“SandboxKey”: “/var/run/docker/netns/4ee191b3751a”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “862c4e78cdebfe61d13301c5e8a0b2284efffda30d7fb75be6300f03ad715671”,
“Gateway”: “172.17.0.1”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“MacAddress”: “02:42:ac:11:00:02”,
“Networks”: {
“bridge”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: null,
“NetworkID”: “c2e04f7ae7d41b43aa29667622f9c35966cb253e507fbec1bdbd9bc3be3228d8”,
“EndpointID”: “862c4e78cdebfe61d13301c5e8a0b2284efffda30d7fb75be6300f03ad715671”,
“Gateway”: “172.17.0.1”,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:11:00:02”
}
}
}
}
]
[[email protected] oo]# curl 172.17.0.2
test

2 案例2:创建私有镜像仓库
2.1 问题

本案例要求创建私有的镜像仓库:
Docker主机:192.168.1.20
镜像仓库服务器:192.168.1.10
2.2 步骤

实现此案例需要按照如下步骤进行。
步骤一:自定义私有仓库

1)定义一个私有仓库
[[email protected] oo]# vim /etc/docker/daemon.json //不写这个文件会报错
{
“insecure-registries” : [“192.168.1.10:5000”] //使用私有仓库运行容器
}
[[email protected] oo]# systemctl restart docker
[[email protected] oo]# docker run -d -p 5000:5000 registry
273be3d1f3280b392cf382f4b74fea53aed58968122eff69fd016f638505ee0e
[[email protected] oo]# curl 192.168.1.10:5000/v2/
{} //出现括号
[[email protected] oo]# docker tag busybox:latest 192.168.1.10:5000/busybox:latest
//打标签
[[email protected] oo]# docker push 192.168.1.10:5000/busybox:latest //上传
[[email protected] oo]# docker tag myos:http 192.168.1.10:5000/myos:http
[[email protected] oo]# docker push 192.168.1.10:5000/myos:http
2)在docker2上面启动
[[email protected] ~]# scp 192.168.1.10:/etc/docker/daemon.json /etc/docker/
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# docker images
[[email protected] ~]# docker run -it 192.168.1.10:5000/myos:http /bin/bash
//直接启动
步骤二:查看私有仓库

1)查看里面有什么镜像
[[email protected] oo]# curl http://192.168.1.10:5000/v2/_catalog
{“repositories”:[“busybox”,”myos”]}
2)查看里面的镜像标签
[[email protected] oo]# curl http://192.168.1.10:5000/v2/busybox/tags/list
{“name”:”busybox”,”tags”:[“latest”]}
[[email protected] oo]# curl http://192.168.1.10:5000/v2/myos/tags/list
{“name”:”myos”,”tags”:[“http”]}

代码如下
1、先自定义一个仓库
先写脚本,不写报错
[[email protected] oo]# vim /etc/docker/daemon.json
[[email protected] oo]# cat /etc/docker/daemon.json
[[email protected] oo]# cat /etc/docker/daemon.json
{
“insecure-registries” : [“192.168.1.10:5000”]
}
重启docker
[[email protected] oo]# systemctl restart docker

[[email protected] oo]# vim /etc/docker/daemon.json
[[email protected] oo]# systemctl restart docker
[[email protected] oo]# cat /etc/docker/daemon.json
{
“insecure-registries” : [“192.168.1.10:5000”]
}
[[email protected] oo]# docker run -d -p 5000:5000 registry
7881a129be72783171cf5ac7cce4cf1c22b8f26d3fec0b3bd90139f400238a08
[[email protected] oo]# ls
Dockerfile local.repo
注意,仓库已经建好了,只是没东西
[[email protected] oo]# curl 192.168.1.10:5000/v2/
{}[[email protected] oo]#
打标签,然后传上去
[[email protected] oo]# docker tag busybox:latest 192.168.1.10:5000/busybox:latest
[[email protected] oo]# docker push 192.168.1.10:5000/busybox:latest
The push refers to a repository [192.168.1.10:5000/busybox]
8a788232037e: Pushed
latest: digest: sha256:e6565c8273423e967c96b5178139e95bee4bd6564700948bb756921c916b4fbe size: 527
[[email protected] oo]# docker tag myos:http 192.168.1.10:5000/myos:http
[[email protected] oo]# docker push 192.168.1.10:5000/myos:http
The push refers to a repository [192.168.1.10:5000/myos]
e90149009e40: Pushed
37f5e846905c: Pushed
c46032f6b564: Pushed
f972d139738d: Pushed
http: digest: sha256:5967dd8c1b9daf34ddaf1cab6b6f8bb0b2edfb991dbce374560b650859e2030f size: 1160

去另外一台机器docker2上面去操作
[[email protected] ~]# scp 192.168.1.10:/etc/docker/daemon.json /etc/docker/
daemon.json 100% 51 3.0KB/s 00:00
[[email protected] ~]# systemctl restart docker
先看一下,没有镜像在docker2上面
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
直接在docker2上面启动,它会自己拉镜像
[[email protected] ~]# docker run -it 192.168.1.10:5000/myos:http /bin/bash
Unable to find image ‘192.168.1.10:5000/myos:http’ locally
http: Pulling from myos

6b21e5259373: Pull complete
3e5e4d7c465a: Pull complete
39c9f23bd4f1: Pull complete
7ff73e8de70f: Pull complete
Digest: sha256:5967dd8c1b9daf34ddaf1cab6b6f8bb0b2edfb991dbce374560b650859e2030f
Status: Downloaded newer image for 192.168.1.10:5000/myos:http
[[email protected] html]# 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 12 bytes 1016 (1016.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6 bytes 508 (508.0 B)
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] html]# exit
exit
现在看一下,有镜像了
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.10:5000/myos http 5edae862ee2e 17 minutes ago 373 MB
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e727361efaf5 192.168.1.10:5000/myos:http “/bin/bash” 15 seconds ago Exited (0) 7 seconds ago agitated_ptolemy

回到docker1,看一下刚才拉的镜像文件
先看下仓库里面的镜像
[[email protected] oo]# curl http://192.168.1.10:5000/v2/_catalog
{“repositories”:[“busybox”,”myos”]}
看下镜像里面的标签
[[email protected] oo]# curl http://192.168.1.10:5000/v2/myos/tags/list
{“name”:”myos”,”tags”:[“http”]}
[[email protected] oo]# curl http://192.168.1.10:5000/v2/busybox/tags/list
{“name”:”busybox”,”tags”:[“latest”]}
[[email protected] oo]#

3 案例3:NFS共享存储
3.1 问题

本案例要求创建NFS共享,能映射到容器里:
服务器创建NFS共享存储,共享目录为/content,权限为rw
客户端挂载共享,并将共享目录映射到容器中
3.2 方案

本方案要求需要一台NFS服务器(NFS用真机代替),ip为192.168.1.254,一台客户端docker1主机,ip为192.168.1.10,一台户端docker2主机,ip为192.168.1.20,实现客户端挂载共享,并将共享目录映射到容器中,docker1更新文件时,docker2实现同步更新,方案如图-2所示:

图-2
3.3 步骤

实现此案例需要按照如下步骤进行。
步骤一:配置NFS服务器
[[email protected] ~]# yum -y install nfs-utils
[[email protected] ~]# mkdir /content
[[email protected] ~]# vim /etc/exports
/content *(rw,no_root_squash)
[[email protected] ~]# systemctl restart nfs-server.service
[[email protected] ~]# systemctl restart nfs-secure.service
[[email protected] ~]# exportfs -rv
exporting *:/content
[[email protected] ~]# chmod 777 /content
[[email protected] ~]# echo 11 > /content/index.html
步骤二:配置客户端

[[email protected] oo]# yum -y install nfs-utils
[[email protected] oo]# systemctl restart nfs-server.service
[[email protected] oo]# showmount -e 192.168.1.254
Export list for 192.168.1.254:
/content *
[[email protected] ~]# mkdir /mnt/qq
[[email protected] ~]# mount -t nfs 192.168.1.254:/content /mnt/qq
[[email protected] ~]# ls /mnt/qq
index.html
[[email protected] ~]# cat /mnt/qq/index.html
11
[[email protected] ~]# docker run -d -p 80:80 -v /mnt/qq:/var/www/html -it myos:http
224248f0df5d795457c43c2a7dad0b7e5ec86abdc3f31d577e72f7929f020e01
[[email protected] ~]# curl 192.168.1.10
11
[[email protected] ~]# yum -y install nfs-utils
[[email protected] ~]# showmount -e 192.168.1.254
Export list for 192.168.1.254:
/content *
[[email protected] ~]# mkdir /mnt/qq
[[email protected] ~]# mount -t nfs 192.168.1.254:/content /mnt/qq
[[email protected] ~]# docker run -d -p 80:80 -v /mnt/qq:/var/www/html -it 192.168.1.10:5000/myos:http
00346dabec2c7a12958da4b7fee6551020249cdcb111ad6a1058352d2838742a
[[email protected] ~]# curl 192.168.1.20
11
[[email protected] ~]# touch /mnt/qq/a.sh
[[email protected] ~]# echo 22 > /mnt/qq/index.html
[[email protected] ~]#ls /mnt/qq/
a.sh index.html
[[email protected] ~]# cat /mnt/qq/index.html
22

1、在真机上配置NFS服务器
[[email protected] ~]# mkdir /content2
[[email protected] ~]# cat /etc/exports
/content/ 172.25.254.0/24(ro)
/content2/ *(rw,no_root_squash)
[[email protected] ~]# systemctl restart nfs-server
[[email protected] ~]# systemctl restart nfs-secure
[[email protected] ~]# exportfs -rv
exporting 172.25.254.0/24:/var/lib/libvirt/images/content
exporting *:/content2
[[email protected] ~]# chmod 777 /content2
[[email protected] ~]# echo 11 > /content2/index.html
[[email protected] ~]# cat /content2/index.html
11

2、配置客户端
在docker1上面操作
先安装NFS组件
[[email protected] oo]# yum install -y nfs-utils
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
12: 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’)
extras | 3.4 kB 00:00:00
loca | 2.9 kB 00:00:00
local_repo | 3.6 kB 00:00:00
updates | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 6.0 MB 00:00:02
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: centos.ustc.edu.cn
正在解决依赖关系
–> 正在检查事务
—> 软件包 nfs-utils.x86_64.1.1.3.0-0.54.el7 将被 安装
–> 正在处理依赖关系 libtirpc >= 0.2.4-0.7,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 gssproxy >= 0.7.0-3,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 rpcbind,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 quota,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libnfsidmap,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libevent,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 keyutils,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libtirpc.so.1()(64bit),它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libnfsidmap.so.0()(64bit),它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libevent-2.0.so.5()(64bit),它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在检查事务
—> 软件包 gssproxy.x86_64.0.0.7.0-17.el7 将被 安装
–> 正在处理依赖关系 libini_config >= 1.3.1-28,它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libverto-module-base,它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libref_array.so.1(REF_ARRAY_0.1.1)(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libini_config.so.3(INI_CONFIG_1.2.0)(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libini_config.so.3(INI_CONFIG_1.1.0)(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libref_array.so.1()(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libini_config.so.3()(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libcollection.so.2()(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libbasicobjects.so.0()(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
—> 软件包 keyutils.x86_64.0.1.5.8-3.el7 将被 安装
—> 软件包 libevent.x86_64.0.2.0.21-4.el7 将被 安装
—> 软件包 libnfsidmap.x86_64.0.0.25-19.el7 将被 安装
—> 软件包 libtirpc.x86_64.0.0.2.4-0.10.el7 将被 安装
—> 软件包 quota.x86_64.1.4.01-17.el7 将被 安装
–> 正在处理依赖关系 quota-nls = 1:4.01-17.el7,它被软件包 1:quota-4.01-17.el7.x86_64 需要
–> 正在处理依赖关系 tcp_wrappers,它被软件包 1:quota-4.01-17.el7.x86_64 需要
—> 软件包 rpcbind.x86_64.0.0.2.0-44.el7 将被 安装
–> 正在检查事务
—> 软件包 libbasicobjects.x86_64.0.0.1.1-29.el7 将被 安装
—> 软件包 libcollection.x86_64.0.0.7.0-29.el7 将被 安装
—> 软件包 libini_config.x86_64.0.1.3.1-29.el7 将被 安装
–> 正在处理依赖关系 libpath_utils.so.1(PATH_UTILS_0.2.1)(64bit),它被软件包 libini_config-1.3.1-29.el7.x86_64 需要
–> 正在处理依赖关系 libpath_utils.so.1()(64bit),它被软件包 libini_config-1.3.1-29.el7.x86_64 需要
—> 软件包 libref_array.x86_64.0.0.1.5-29.el7 将被 安装
—> 软件包 libverto-libevent.x86_64.0.0.2.5-4.el7 将被 安装
—> 软件包 quota-nls.noarch.1.4.01-17.el7 将被 安装
—> 软件包 tcp_wrappers.x86_64.0.7.6-77.el7 将被 安装
–> 正在检查事务
—> 软件包 libpath_utils.x86_64.0.0.2.1-29.el7 将被 安装
–> 处理 gssproxy-0.7.0-17.el7.x86_64 与 selinux-policy < 3.13.1-166.el7.noarch 的冲突
–> 正在使用新的信息重新解决依赖关系
–> 正在检查事务
—> 软件包 selinux-policy.noarch.0.3.13.1-166.el7 将被 升级
–> 正在处理依赖关系 selinux-policy = 3.13.1-166.el7,它被软件包 selinux-policy-targeted-3.13.1-166.el7.noarch 需要
–> 正在处理依赖关系 selinux-policy = 3.13.1-166.el7,它被软件包 selinux-policy-targeted-3.13.1-166.el7.noarch 需要
—> 软件包 selinux-policy.noarch.0.3.13.1-192.el7_5.6 将被 更新
–> 正在检查事务
—> 软件包 selinux-policy-targeted.noarch.0.3.13.1-166.el7 将被 升级
—> 软件包 selinux-policy-targeted.noarch.0.3.13.1-192.el7_5.6 将被 更新
–> 解决依赖关系完成

依赖关系解决

================================================================================================================================
Package 架构 版本 源 大小
================================================================================================================================
正在安装:
nfs-utils x86_64 1:1.3.0-0.54.el7 base 407 k
正在更新:
selinux-policy noarch 3.13.1-192.el7_5.6 updates 453 k
为依赖而安装:
gssproxy x86_64 0.7.0-17.el7 base 108 k
keyutils x86_64 1.5.8-3.el7 base 54 k
libbasicobjects x86_64 0.1.1-29.el7 base 25 k
libcollection x86_64 0.7.0-29.el7 base 41 k
libevent x86_64 2.0.21-4.el7 base 214 k
libini_config x86_64 1.3.1-29.el7 base 63 k
libnfsidmap x86_64 0.25-19.el7 base 50 k
libpath_utils x86_64 0.2.1-29.el7 base 28 k
libref_array x86_64 0.1.5-29.el7 base 26 k
libtirpc x86_64 0.2.4-0.10.el7 base 88 k
libverto-libevent x86_64 0.2.5-4.el7 base 8.9 k
quota x86_64 1:4.01-17.el7 base 179 k
quota-nls noarch 1:4.01-17.el7 base 90 k
rpcbind x86_64 0.2.0-44.el7 base 59 k
tcp_wrappers x86_64 7.6-77.el7 base 78 k
为依赖而更新:
selinux-policy-targeted noarch 3.13.1-192.el7_5.6 updates 6.6 M

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

总下载量:8.5 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/18): keyutils-1.5.8-3.el7.x86_64.rpm | 54 kB 00:00:00
(2/18): gssproxy-0.7.0-17.el7.x86_64.rpm | 108 kB 00:00:01
(3/18): libbasicobjects-0.1.1-29.el7.x86_64.rpm | 25 kB 00:00:00
(4/18): libcollection-0.7.0-29.el7.x86_64.rpm | 41 kB 00:00:00
(5/18): libini_config-1.3.1-29.el7.x86_64.rpm | 63 kB 00:00:00
(6/18): libevent-2.0.21-4.el7.x86_64.rpm | 214 kB 00:00:00
(7/18): libnfsidmap-0.25-19.el7.x86_64.rpm | 50 kB 00:00:00
(8/18): libpath_utils-0.2.1-29.el7.x86_64.rpm | 28 kB 00:00:00
(9/18): libref_array-0.1.5-29.el7.x86_64.rpm | 26 kB 00:00:00
(10/18): libtirpc-0.2.4-0.10.el7.x86_64.rpm | 88 kB 00:00:00
(11/18): libverto-libevent-0.2.5-4.el7.x86_64.rpm | 8.9 kB 00:00:00
(12/18): nfs-utils-1.3.0-0.54.el7.x86_64.rpm | 407 kB 00:00:00
(13/18): quota-4.01-17.el7.x86_64.rpm | 179 kB 00:00:00
(14/18): quota-nls-4.01-17.el7.noarch.rpm | 90 kB 00:00:00
(15/18): rpcbind-0.2.0-44.el7.x86_64.rpm | 59 kB 00:00:00
(16/18): tcp_wrappers-7.6-77.el7.x86_64.rpm | 78 kB 00:00:00
(17/18): selinux-policy-3.13.1-192.el7_5.6.noarch.rpm | 453 kB 00:00:01
(18/18): selinux-policy-targeted-3.13.1-192.el7_5.6.noarch.rpm | 6.6 MB 00:00:02
——————————————————————————————————————————–
总计 1.6 MB/s | 8.5 MB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : libbasicobjects-0.1.1-29.el7.x86_64 1/20
正在安装 : libref_array-0.1.5-29.el7.x86_64 2/20
正在安装 : libcollection-0.7.0-29.el7.x86_64 3/20
正在安装 : libevent-2.0.21-4.el7.x86_64 4/20
正在安装 : libtirpc-0.2.4-0.10.el7.x86_64 5/20
正在安装 : rpcbind-0.2.0-44.el7.x86_64 6/20
正在安装 : libverto-libevent-0.2.5-4.el7.x86_64 7/20
正在安装 : libpath_utils-0.2.1-29.el7.x86_64 8/20
正在安装 : libini_config-1.3.1-29.el7.x86_64 9/20
正在安装 : gssproxy-0.7.0-17.el7.x86_64 10/20
正在安装 : tcp_wrappers-7.6-77.el7.x86_64 11/20
正在安装 : keyutils-1.5.8-3.el7.x86_64 12/20
正在安装 : libnfsidmap-0.25-19.el7.x86_64 13/20
正在更新 : selinux-policy-3.13.1-192.el7_5.6.noarch 14/20
正在安装 : 1:quota-nls-4.01-17.el7.noarch 15/20
正在安装 : 1:quota-4.01-17.el7.x86_64 16/20
正在安装 : 1:nfs-utils-1.3.0-0.54.el7.x86_64 17/20
正在更新 : selinux-policy-targeted-3.13.1-192.el7_5.6.noarch 18/20
清理 : selinux-policy-targeted-3.13.1-166.el7.noarch 19/20
清理 : selinux-policy-3.13.1-166.el7.noarch 20/20
验证中 : 1:quota-nls-4.01-17.el7.noarch 1/20
验证中 : libini_config-1.3.1-29.el7.x86_64 2/20
验证中 : selinux-policy-3.13.1-192.el7_5.6.noarch 3/20
验证中 : libtirpc-0.2.4-0.10.el7.x86_64 4/20
验证中 : libnfsidmap-0.25-19.el7.x86_64 5/20
验证中 : selinux-policy-targeted-3.13.1-192.el7_5.6.noarch 6/20
验证中 : libevent-2.0.21-4.el7.x86_64 7/20
验证中 : keyutils-1.5.8-3.el7.x86_64 8/20
验证中 : libverto-libevent-0.2.5-4.el7.x86_64 9/20
验证中 : tcp_wrappers-7.6-77.el7.x86_64 10/20
验证中 : gssproxy-0.7.0-17.el7.x86_64 11/20
验证中 : libcollection-0.7.0-29.el7.x86_64 12/20
验证中 : rpcbind-0.2.0-44.el7.x86_64 13/20
验证中 : 1:nfs-utils-1.3.0-0.54.el7.x86_64 14/20
验证中 : libref_array-0.1.5-29.el7.x86_64 15/20
验证中 : 1:quota-4.01-17.el7.x86_64 16/20
验证中 : libpath_utils-0.2.1-29.el7.x86_64 17/20
验证中 : libbasicobjects-0.1.1-29.el7.x86_64 18/20
验证中 : selinux-policy-3.13.1-166.el7.noarch 19/20
验证中 : selinux-policy-targeted-3.13.1-166.el7.noarch 20/20

已安装:
nfs-utils.x86_64 1:1.3.0-0.54.el7

作为依赖被安装:
gssproxy.x86_64 0:0.7.0-17.el7 keyutils.x86_64 0:1.5.8-3.el7 libbasicobjects.x86_64 0:0.1.1-29.el7
libcollection.x86_64 0:0.7.0-29.el7 libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.3.1-29.el7
libnfsidmap.x86_64 0:0.25-19.el7 libpath_utils.x86_64 0:0.2.1-29.el7 libref_array.x86_64 0:0.1.5-29.el7
libtirpc.x86_64 0:0.2.4-0.10.el7 libverto-libevent.x86_64 0:0.2.5-4.el7 quota.x86_64 1:4.01-17.el7
quota-nls.noarch 1:4.01-17.el7 rpcbind.x86_64 0:0.2.0-44.el7 tcp_wrappers.x86_64 0:7.6-77.el7

更新完毕:
selinux-policy.noarch 0:3.13.1-192.el7_5.6

作为依赖被升级:
selinux-policy-targeted.noarch 0:3.13.1-192.el7_5.6

完毕!

将真机上创建的/content2挂载到虚拟机
[[email protected] oo]# systemctl restart nfs-server
[[email protected] oo]# showmount -e 192.168.1.254
Export list for 192.168.1.254:
/content2 *
/var/lib/libvirt/images/content 172.25.254.0/24
[[email protected] oo]# mkdir /mnt/qq
[[email protected] oo]# mount -t nfs 192.168.1.254:/content2 /mnt/qq
[[email protected] oo]# ls /mnt/qq
index.html
[[email protected] oo]# cat /mnt/qq/index.html
11
[[email protected] oo]# docker run -d -p 80:80 -v /mnt/qq:/var/www/html -it 192.168.1.10:5000/myos:http
c51b61e6a923753beb31f2b710e4c17298f0e140372fa6568d575e7865d88f5b
[[email protected] oo]# curl 192.168.1.10
11
[[email protected] oo]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c51b61e6a923 192.168.1.10:5000/myos:http “/usr/sbin/httpd -DFO” 22 seconds ago Up 19 seconds 0.0.0.0:80->80/tcp mad_liskov
7881a129be72 registry “/entrypoint.sh /etc/” 2 hours ago Up 2 hours 0.0.0.0:5000->5000/tcp condescending_kirch
[[email protected] oo]#

现在换到docker2上来操作
[[email protected] ~]# yum install -y nfs-utils
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
loca | 2.9 kB 00:00:00
local_repo | 3.6 kB 00:00:00
updates | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 6.0 MB 00:00:02
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.cn99.com
* updates: mirrors.163.com
正在解决依赖关系
–> 正在检查事务
—> 软件包 nfs-utils.x86_64.1.1.3.0-0.54.el7 将被 安装
–> 正在处理依赖关系 libtirpc >= 0.2.4-0.7,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 gssproxy >= 0.7.0-3,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 rpcbind,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 quota,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libnfsidmap,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libevent,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 keyutils,它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libtirpc.so.1()(64bit),它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libnfsidmap.so.0()(64bit),它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在处理依赖关系 libevent-2.0.so.5()(64bit),它被软件包 1:nfs-utils-1.3.0-0.54.el7.x86_64 需要
–> 正在检查事务
—> 软件包 gssproxy.x86_64.0.0.7.0-17.el7 将被 安装
–> 正在处理依赖关系 libini_config >= 1.3.1-28,它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libverto-module-base,它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libref_array.so.1(REF_ARRAY_0.1.1)(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libini_config.so.3(INI_CONFIG_1.2.0)(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libini_config.so.3(INI_CONFIG_1.1.0)(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libref_array.so.1()(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libini_config.so.3()(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libcollection.so.2()(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
–> 正在处理依赖关系 libbasicobjects.so.0()(64bit),它被软件包 gssproxy-0.7.0-17.el7.x86_64 需要
—> 软件包 keyutils.x86_64.0.1.5.8-3.el7 将被 安装
—> 软件包 libevent.x86_64.0.2.0.21-4.el7 将被 安装
—> 软件包 libnfsidmap.x86_64.0.0.25-19.el7 将被 安装
—> 软件包 libtirpc.x86_64.0.0.2.4-0.10.el7 将被 安装
—> 软件包 quota.x86_64.1.4.01-17.el7 将被 安装
–> 正在处理依赖关系 quota-nls = 1:4.01-17.el7,它被软件包 1:quota-4.01-17.el7.x86_64 需要
–> 正在处理依赖关系 tcp_wrappers,它被软件包 1:quota-4.01-17.el7.x86_64 需要
—> 软件包 rpcbind.x86_64.0.0.2.0-44.el7 将被 安装
–> 正在检查事务
—> 软件包 libbasicobjects.x86_64.0.0.1.1-29.el7 将被 安装
—> 软件包 libcollection.x86_64.0.0.7.0-29.el7 将被 安装
—> 软件包 libini_config.x86_64.0.1.3.1-29.el7 将被 安装
–> 正在处理依赖关系 libpath_utils.so.1(PATH_UTILS_0.2.1)(64bit),它被软件包 libini_config-1.3.1-29.el7.x86_64 需要
–> 正在处理依赖关系 libpath_utils.so.1()(64bit),它被软件包 libini_config-1.3.1-29.el7.x86_64 需要
—> 软件包 libref_array.x86_64.0.0.1.5-29.el7 将被 安装
—> 软件包 libverto-libevent.x86_64.0.0.2.5-4.el7 将被 安装
—> 软件包 quota-nls.noarch.1.4.01-17.el7 将被 安装
—> 软件包 tcp_wrappers.x86_64.0.7.6-77.el7 将被 安装
–> 正在检查事务
—> 软件包 libpath_utils.x86_64.0.0.2.1-29.el7 将被 安装
–> 处理 gssproxy-0.7.0-17.el7.x86_64 与 selinux-policy < 3.13.1-166.el7.noarch 的冲突
–> 正在使用新的信息重新解决依赖关系
–> 正在检查事务
—> 软件包 selinux-policy.noarch.0.3.13.1-166.el7 将被 升级
–> 正在处理依赖关系 selinux-policy = 3.13.1-166.el7,它被软件包 selinux-policy-targeted-3.13.1-166.el7.noarch 需要
–> 正在处理依赖关系 selinux-policy = 3.13.1-166.el7,它被软件包 selinux-policy-targeted-3.13.1-166.el7.noarch 需要
—> 软件包 selinux-policy.noarch.0.3.13.1-192.el7_5.6 将被 更新
–> 正在检查事务
—> 软件包 selinux-policy-targeted.noarch.0.3.13.1-166.el7 将被 升级
—> 软件包 selinux-policy-targeted.noarch.0.3.13.1-192.el7_5.6 将被 更新
–> 解决依赖关系完成

依赖关系解决

================================================================================================================================
Package 架构 版本 源 大小
================================================================================================================================
正在安装:
nfs-utils x86_64 1:1.3.0-0.54.el7 base 407 k
正在更新:
selinux-policy noarch 3.13.1-192.el7_5.6 updates 453 k
为依赖而安装:
gssproxy x86_64 0.7.0-17.el7 base 108 k
keyutils x86_64 1.5.8-3.el7 base 54 k
libbasicobjects x86_64 0.1.1-29.el7 base 25 k
libcollection x86_64 0.7.0-29.el7 base 41 k
libevent x86_64 2.0.21-4.el7 base 214 k
libini_config x86_64 1.3.1-29.el7 base 63 k
libnfsidmap x86_64 0.25-19.el7 base 50 k
libpath_utils x86_64 0.2.1-29.el7 base 28 k
libref_array x86_64 0.1.5-29.el7 base 26 k
libtirpc x86_64 0.2.4-0.10.el7 base 88 k
libverto-libevent x86_64 0.2.5-4.el7 base 8.9 k
quota x86_64 1:4.01-17.el7 base 179 k
quota-nls noarch 1:4.01-17.el7 base 90 k
rpcbind x86_64 0.2.0-44.el7 base 59 k
tcp_wrappers x86_64 7.6-77.el7 base 78 k
为依赖而更新:
selinux-policy-targeted noarch 3.13.1-192.el7_5.6 updates 6.6 M

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

总下载量:8.5 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/18): keyutils-1.5.8-3.el7.x86_64.rpm | 54 kB 00:00:00
(2/18): gssproxy-0.7.0-17.el7.x86_64.rpm | 108 kB 00:00:00
(3/18): libbasicobjects-0.1.1-29.el7.x86_64.rpm | 25 kB 00:00:00
(4/18): libcollection-0.7.0-29.el7.x86_64.rpm | 41 kB 00:00:00
(5/18): libini_config-1.3.1-29.el7.x86_64.rpm | 63 kB 00:00:00
(6/18): libevent-2.0.21-4.el7.x86_64.rpm | 214 kB 00:00:00
(7/18): libnfsidmap-0.25-19.el7.x86_64.rpm | 50 kB 00:00:00
(8/18): libpath_utils-0.2.1-29.el7.x86_64.rpm | 28 kB 00:00:00
(9/18): libref_array-0.1.5-29.el7.x86_64.rpm | 26 kB 00:00:00
(10/18): libtirpc-0.2.4-0.10.el7.x86_64.rpm | 88 kB 00:00:00
(11/18): libverto-libevent-0.2.5-4.el7.x86_64.rpm | 8.9 kB 00:00:00
(12/18): nfs-utils-1.3.0-0.54.el7.x86_64.rpm | 407 kB 00:00:00
(13/18): quota-4.01-17.el7.x86_64.rpm | 179 kB 00:00:00
(14/18): quota-nls-4.01-17.el7.noarch.rpm | 90 kB 00:00:00
(15/18): rpcbind-0.2.0-44.el7.x86_64.rpm | 59 kB 00:00:00
(16/18): tcp_wrappers-7.6-77.el7.x86_64.rpm | 78 kB 00:00:00
(17/18): selinux-policy-3.13.1-192.el7_5.6.noarch.rpm | 453 kB 00:00:01
(18/18): selinux-policy-targeted-3.13.1-192.el7_5.6.noarch.rpm | 6.6 MB 00:00:02
——————————————————————————————————————————–
总计 1.6 MB/s | 8.5 MB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : libbasicobjects-0.1.1-29.el7.x86_64 1/20
正在安装 : libref_array-0.1.5-29.el7.x86_64 2/20
正在安装 : libcollection-0.7.0-29.el7.x86_64 3/20
正在安装 : libevent-2.0.21-4.el7.x86_64 4/20
正在安装 : libtirpc-0.2.4-0.10.el7.x86_64 5/20
正在安装 : rpcbind-0.2.0-44.el7.x86_64 6/20
正在安装 : libverto-libevent-0.2.5-4.el7.x86_64 7/20
正在安装 : libpath_utils-0.2.1-29.el7.x86_64 8/20
正在安装 : libini_config-1.3.1-29.el7.x86_64 9/20
正在安装 : gssproxy-0.7.0-17.el7.x86_64 10/20
正在安装 : tcp_wrappers-7.6-77.el7.x86_64 11/20
正在安装 : keyutils-1.5.8-3.el7.x86_64 12/20
正在安装 : libnfsidmap-0.25-19.el7.x86_64 13/20
正在更新 : selinux-policy-3.13.1-192.el7_5.6.noarch 14/20
正在安装 : 1:quota-nls-4.01-17.el7.noarch 15/20
正在安装 : 1:quota-4.01-17.el7.x86_64 16/20
正在安装 : 1:nfs-utils-1.3.0-0.54.el7.x86_64 17/20
正在更新 : selinux-policy-targeted-3.13.1-192.el7_5.6.noarch 18/20
清理 : selinux-policy-targeted-3.13.1-166.el7.noarch 19/20
清理 : selinux-policy-3.13.1-166.el7.noarch 20/20
验证中 : 1:quota-nls-4.01-17.el7.noarch 1/20
验证中 : libini_config-1.3.1-29.el7.x86_64 2/20
验证中 : selinux-policy-3.13.1-192.el7_5.6.noarch 3/20
验证中 : libtirpc-0.2.4-0.10.el7.x86_64 4/20
验证中 : libnfsidmap-0.25-19.el7.x86_64 5/20
验证中 : selinux-policy-targeted-3.13.1-192.el7_5.6.noarch 6/20
验证中 : libevent-2.0.21-4.el7.x86_64 7/20
验证中 : keyutils-1.5.8-3.el7.x86_64 8/20
验证中 : libverto-libevent-0.2.5-4.el7.x86_64 9/20
验证中 : tcp_wrappers-7.6-77.el7.x86_64 10/20
验证中 : gssproxy-0.7.0-17.el7.x86_64 11/20
验证中 : libcollection-0.7.0-29.el7.x86_64 12/20
验证中 : rpcbind-0.2.0-44.el7.x86_64 13/20
验证中 : 1:nfs-utils-1.3.0-0.54.el7.x86_64 14/20
验证中 : libref_array-0.1.5-29.el7.x86_64 15/20
验证中 : 1:quota-4.01-17.el7.x86_64 16/20
验证中 : libpath_utils-0.2.1-29.el7.x86_64 17/20
验证中 : libbasicobjects-0.1.1-29.el7.x86_64 18/20
验证中 : selinux-policy-3.13.1-166.el7.noarch 19/20
验证中 : selinux-policy-targeted-3.13.1-166.el7.noarch 20/20

已安装:
nfs-utils.x86_64 1:1.3.0-0.54.el7

作为依赖被安装:
gssproxy.x86_64 0:0.7.0-17.el7 keyutils.x86_64 0:1.5.8-3.el7 libbasicobjects.x86_64 0:0.1.1-29.el7
libcollection.x86_64 0:0.7.0-29.el7 libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.3.1-29.el7
libnfsidmap.x86_64 0:0.25-19.el7 libpath_utils.x86_64 0:0.2.1-29.el7 libref_array.x86_64 0:0.1.5-29.el7
libtirpc.x86_64 0:0.2.4-0.10.el7 libverto-libevent.x86_64 0:0.2.5-4.el7 quota.x86_64 1:4.01-17.el7
quota-nls.noarch 1:4.01-17.el7 rpcbind.x86_64 0:0.2.0-44.el7 tcp_wrappers.x86_64 0:7.6-77.el7

更新完毕:
selinux-policy.noarch 0:3.13.1-192.el7_5.6

作为依赖被升级:
selinux-policy-targeted.noarch 0:3.13.1-192.el7_5.6

完毕!
挂载并创建容器
[[email protected] ~]# showmount -e 192.168.1.254
Export list for 192.168.1.254:
/content2 *
/var/lib/libvirt/images/content 172.25.254.0/24
[[email protected] ~]# mkdir /mnt/qq
[[email protected] ~]# mount -t nfs 192.168.1.254:/content2 /mnt/qq
[[email protected] ~]# ll /mnt/qq
总用量 4
-rw-r–r– 1 root root 3 10月 18 16:13 index.html
[[email protected] ~]# cat /mnt/qq/index.html
11
[[email protected] ~]# docker run -d -p 80:80 -v /mnt/qq:/var/www/html -it 192.168.1.10:5000/myos:http
4914bb905d07dc51f679af0a1da0ee2a13633d9720e34f77d01d7c4f0a864976
[[email protected] ~]# curl 192.168.1.20
11
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4914bb905d07 192.168.1.10:5000/myos:http “/usr/sbin/httpd -DFO” 49 seconds ago Up 46 seconds 0.0.0.0:80->80/tcp boring_davinci

关键的地方来了,NFS全两个容器共享的
在docker1上面,修改挂载的内容
[[email protected] oo]# touch /mnt/qq/a.sh
[[email protected] oo]# echo 22 >/mnt/qq/index.html
[[email protected] oo]# curl 192.168.1.10
22
来到docker2,可以看到,也已经被修改了,因为共享的是一块盘
[[email protected] ~]# ls /mnt/qq
a.sh index.html
[[email protected] ~]# cat /mnt/qq/index.html
22
[[email protected] ~]# curl 192.168.1.20
22

4 案例4:创建自定义网桥
4.1 问题

本案例要求:
创建网桥设备docker01
设定网段为172.30.0.0/16
启动nginx容器,nginx容器桥接docker01设备
映射真实机8080端口与容器的80端口
4.2 步骤

实现此案例需要按照如下步骤进行。
步骤一:新建Docker网络模型

1)新建docker1网络模型
[[email protected] ~]# docker network create –subnet=172.30.0.0/16 docker01
c9cf26f911ef2dccb1fd1f670a6c51491e72b49133246f6428dd732c44109462
[[email protected] ~]# docker network list
NETWORK ID NAME DRIVER SCOPE
bc189673f959 bridge bridge local
6622752788ea docker01 bridge local
53bf43bdd584 host host local
ac52d3151ba8 none null local
[[email protected] ~]# ip a s
[[email protected] ~]# docker network inspect docker01
[
{
“Name”: “docker01”,
“Id”: “c9cf26f911ef2dccb1fd1f670a6c51491e72b49133246f6428dd732c44109462”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: {},
“Config”: [
{
“Subnet”: “172.30.0.0/16”
}
]
},
“Internal”: false,
“Containers”: {},
“Options”: {},
“Labels”: {}
}
]
2)使用自定义网桥启动容器
[[email protected] ~]# docker run –network=docker01 -id nginx
3)端口映射
[[email protected] ~]# docker run -p 8080:80 -id nginx
e523b386f9d6194e53d0a5b6b8f5ab4984d062896bab10639e41aef657cb2a53
[[email protected] ~]# curl 192.168.1.10:8080
步骤二:扩展实验

1)新建一个网络模型docker02
[[email protected] ~]# docker network create –driver bridge docker02
//新建一个 名为docker02的网络模型
5496835bd3f53ac220ce3d8be71ce6afc919674711ab3f94e6263b9492c7d2cc
[[email protected] ~]# ifconfig
//但是在用ifconfig命令查看的时候,显示的名字并不是docker02,而是br-5496835bd3f5
br-5496835bd3f5: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:89:6a:a2:72 txqueuelen 0 (Ethernet)
RX packets 8 bytes 496 (496.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 496 (496.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[[email protected] ~]# docker network list //查看显示docker02(查看加粗字样)
NETWORK ID NAME DRIVER SCOPE
bc189673f959 bridge bridge local
5496835bd3f5 docker02 bridge local
53bf43bdd584 host host local
ac52d3151ba8 none null local
2)若要解决使用ifconfig命令可以看到docker02的问题,可以执行以下几步命令
[[email protected] ~]# docker network list //查看docker0的NETWORK ID(加粗字样)
NETWORK ID NAME DRIVER SCOPE
bc189673f959 bridge bridge local
5496835bd3f5 docker02 bridge local
53bf43bdd584 host host local
ac52d3151ba8 none null local
3)查看16dc92e55023的信息,如图-3所示:
[[email protected] ~]# docker network inspect bc189673f959

图-3
4)查看图片的倒数第六行有”com.docker.network.bridge.name”: “docker0″字样
5)把刚刚创建的docker02网桥删掉
[[email protected] ~]# docker network rm docker02 //删除docker02
docker02
[[email protected] ~]# docker network create \
docker02 -o com.docker.network.bridge.name=docker02
//创建docker02网桥
648bd5da03606d5a1a395c098662b5f820b9400c6878e2582a7ce754c8c05a3a
[[email protected] ~]# ifconfig //ifconfig查看有docker02
docker02: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:94:27:a0:43 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
6)若想在创建docker03的时候自定义网段(之前已经创建过docker01和02,这里用docker03),执行以下命令
[[email protected] ~]# docker network create docker03 –subnet=172.30.0.0/16 -o com.docker.network.bridge.name=docker03
f003aa1c0fa20c81e4f73c12dcc79262f1f1d67589d7440175ea01dc0be4d03c
[[email protected] ~]# ifconfig //ifconfig查看,显示的是自己定义的网段
docker03: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.30.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:27:9b:95:b3 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

代码如下
先创建一个docker01网桥,网段设置为172.30.0.0/16
[[email protected] oo]# docker network create –subnet=172.30.0.0/16 docker01
2e0cf6d4339563626f532ec13e15c6305f69cb1cb4dd8154812caaf17a083f99
[[email protected] oo]# docker network list
NETWORK ID NAME DRIVER SCOPE
f4e72bc4fa54 bridge bridge local
2e0cf6d43395 docker01 bridge local
6a011995dd07 host host local
ab00cd5184a5 none null local
[[email protected] oo]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:c2:e0:da brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fec2:e0da/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 02:42:21:3e:ef:66 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:21ff:fe3e:ef66/64 scope link
valid_lft forever preferred_lft forever
11: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP
link/ether da:d3:ae:80:a2:a7 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::d8d3:aeff:fe80:a2a7/64 scope link
valid_lft forever preferred_lft forever
15: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP
link/ether a6:5f:ce:40:07:8d brd ff:ff:ff:ff:ff:ff link-netnsid 1
inet6 fe80::a45f:ceff:fe40:78d/64 scope link
valid_lft forever preferred_lft forever
16: br-2e0cf6d43395: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:9f:87:55:03 brd ff:ff:ff:ff:ff:ff
inet 172.30.0.1/16 scope global br-2e0cf6d43395
valid_lft forever preferred_lft forever
[[email protected] oo]#
[[email protected] oo]# docker network inspect docker01
[
{
“Name”: “docker01”,
“Id”: “2e0cf6d4339563626f532ec13e15c6305f69cb1cb4dd8154812caaf17a083f99”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: {},
“Config”: [
{
“Subnet”: “172.30.0.0/16”
}
]
},
“Internal”: false,
“Containers”: {},
“Options”: {},
“Labels”: {}
}
]

使用刚才自定义的网桥创建一个容器
[[email protected] oo]# docker run –network=docker01 -id nginx
12aaca174ba86a662ddb7422acaa885c5e4d9abe5fe00d5d1a07d4b7d85c1671

再创建一个容器(跟上面的容器没有任何关系!),但是着一个做一个端口映射
[[email protected] oo]# docker run -p 8080:80 -id nginx
e02fdcb6bacb5a097a7f44a852d5c328b61d004a8e3d897949753f2eb5473d36
访问一下试试看
[[email protected] oo]# curl 192.168.1.10:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href=”http://nginx.org/”>nginx.org</a>.<br/>
Commercial support is available at
<a href=”http://nginx.com/”>nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

拓展实验
[[email protected] oo]# docker network create –driver bridge docker02
24b74c4ccfebfcb55e5b6dd15ff323a2623a756699ed7d5d6338c22aad7a7272
[[email protected] oo]# ifconfig
br-24b74c4ccfeb: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:f6:3a:dc:4c txqueuelen 0 (Ethernet)
RX packets 25565 bytes 42485271 (40.5 MiB)
RX errors 0 dropped 19 overruns 0 frame 0
TX packets 15633 bytes 146315270 (139.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

br-2e0cf6d43395: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.30.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:9fff:fe87:5503 prefixlen 64 scopeid 0x20<link>
ether 02:42:9f:87:55:03 txqueuelen 0 (Ethernet)
RX packets 8 bytes 648 (648.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 1296 (1.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:21ff:fe3e:ef66 prefixlen 64 scopeid 0x20<link>
ether 02:42:21:3e:ef:66 txqueuelen 0 (Ethernet)
RX packets 14045 bytes 145641611 (138.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18775 bytes 172406369 (164.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

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 25565 bytes 42485271 (40.5 MiB)
RX errors 0 dropped 19 overruns 0 frame 0
TX packets 15633 bytes 146315270 (139.5 MiB)
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 2 bytes 196 (196.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 196 (196.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

veth0dbf9c6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::d8d3:aeff:fe80:a2a7 prefixlen 64 scopeid 0x20<link>
ether da:d3:ae:80:a2:a7 txqueuelen 0 (Ethernet)
RX packets 13272 bytes 145783958 (139.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 17694 bytes 146814855 (140.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

veth5622b41: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::b408:27ff:fe07:5ffa prefixlen 64 scopeid 0x20<link>
ether b6:08:27:07:5f:fa txqueuelen 0 (Ethernet)
RX packets 8 bytes 648 (648.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 1296 (1.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

vethaca4ee2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::a45f:ceff:fe40:78d prefixlen 64 scopeid 0x20<link>
ether a6:5f:ce:40:07:8d txqueuelen 0 (Ethernet)
RX packets 20 bytes 1844 (1.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 34 bytes 2508 (2.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

vethf1388a5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::54cf:61ff:fe1d:b94 prefixlen 64 scopeid 0x20<link>
ether 56:cf:61:1d:0b:94 txqueuelen 0 (Ethernet)
RX packets 15 bytes 1920 (1.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 17 bytes 1283 (1.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
##################################################
注意细节,虽然创建的是docker02,但是显示的名称是ID号24b74
[[email protected] oo]# docker network create –driver bridge docker02
24b74c4ccfebfcb55e5b6dd15ff323a2623a756699ed7d5d6338c22aad7a7272
[[email protected] oo]# ifconfig
br-24b74c4ccfeb: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:f6:3a:dc:4c txqueuelen 0 (Ethernet)
RX packets 25565 bytes 42485271 (40.5 MiB)
RX errors 0 dropped 19 overruns 0 frame 0
TX packets 15633 bytes 146315270 (139.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

那如何解决这个问题,那就要在创建网桥时指定名称
[[email protected] oo]# docker network list
NETWORK ID NAME DRIVER SCOPE
f4e72bc4fa54 bridge bridge local
2e0cf6d43395 docker01 bridge local
24b74c4ccfeb docker02 bridge local
6a011995dd07 host host local
ab00cd5184a5 none null local

[[email protected] oo]# docker network list
NETWORK ID NAME DRIVER SCOPE
f4e72bc4fa54 bridge bridge local
2e0cf6d43395 docker01 bridge local
24b74c4ccfeb docker02 bridge local
6a011995dd07 host host local
ab00cd5184a5 none null local
[[email protected] oo]#
[[email protected] oo]# docker network inspect 24b
[
{
“Name”: “docker02”,
“Id”: “24b74c4ccfebfcb55e5b6dd15ff323a2623a756699ed7d5d6338c22aad7a7272”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: {},
“Config”: [
{
“Subnet”: “172.18.0.0/16”,
“Gateway”: “172.18.0.1/16”
}
]
},
“Internal”: false,
“Containers”: {},
“Options”: {},
“Labels”: {}
}
]
删除原来的网桥
[[email protected] oo]# docker network rm docker02
docker02
重新创建的时候指定名称为docker02
[[email protected] oo]# docker network create docker02 -o com.docker.network.bridge.name=docker02
100619b52f2d3ebb9f6982ffcf9289a610300c46bcdf460c77d2356c7dc7d013
[[email protected] oo]# ifconfig
br-2e0cf6d43395: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.30.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:9fff:fe87:5503 prefixlen 64 scopeid 0x20<link>
ether 02:42:9f:87:55:03 txqueuelen 0 (Ethernet)
RX packets 8 bytes 648 (648.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 1296 (1.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:21ff:fe3e:ef66 prefixlen 64 scopeid 0x20<link>
ether 02:42:21:3e:ef:66 txqueuelen 0 (Ethernet)
RX packets 14045 bytes 145641611 (138.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18775 bytes 172406369 (164.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

docker02: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:ed:81:39:9e 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] oo]# docker network create docker03 –subnet=172.70.0.0/16 -o com.docker.network.bridge.name=docker03
676c05910a3ff4b0849c394dfdfe4a2ea026c270b91d8e0961e45a66e9730914
[[email protected] oo]# ifconfig docker03
docker03: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.70.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:c3:4b:f4:31 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

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

发表评论

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