docker2

自己创建新容器

[root@docker02 ~]# docker rm $(docker stop $(docker ps -qa))
2ed6c524e9bf

[root@docker02 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[root@docker02 ~]# docker run -it centos

[root@d168dedc4931 /]# cd /etc/yum.repos.d
[root@d168dedc4931 yum.repos.d]# rm -rf *
[root@d168dedc4931 yum.repos.d]# vi centos.repo
[centos]
name=centos
baseurl=ftp://192.168.3.254/CentOS7
enabled=1
gpgcheck=0

[root@d168dedc4931 yum.repos.d]# yum clean all
[root@d168dedc4931 yum.repos.d]# yum -y install net-tools iproute psmisc vim-enhanced

[root@d168dedc4931 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
... ...

[root@d168dedc4931 yum.repos.d]# exit
exit

[root@docker02 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[root@docker02 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d168dedc4931 centos "/bin/bash" 3 minutes ago Exited (0) 28 seconds ago serene_varahamihira

[root@docker02 ~]# docker commit d168dedc4931 myos:latest
sha256:99b9412c6de21e379aa03ebf124439606e1aa023775c0613e58f21788cb661b5

[root@docker02 ~]# docker images 可以看到大小,myos在复制了centos的基础上加工而成的
REPOSITORY TAG IMAGE ID CREATED SIZE
myos latest 99b9412c6de2 6 seconds ago 313.8 MB
centos latest e934aafc2206 8 months ago 198.6 MB
... ...

[root@docker02 ~]# docker history centos 查看镜像centos的制作历史,它id号是e934aafc2206
IMAGE CREATED CREATED BY SIZE COMMENT
e934aafc2206 8 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 8 months ago /bin/sh -c #(nop) LABEL org.label-schema.sch 0 B
<missing> 8 months ago /bin/sh -c #(nop) ADD file:f755805244a649ecca 198.6 MB

[root@docker02 ~]# docker history myos 查看镜像myos的制作历史,它id号是99b9412c6de2,后端盘id号e934aafc2206,即centos
IMAGE CREATED CREATED BY SIZE COMMENT
99b9412c6de2 4 minutes ago /bin/bash 115.2 MB
e934aafc2206 8 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 8 months ago /bin/sh -c #(nop) LABEL org.label-schema.sch 0 B
<missing> 8 months ago /bin/sh -c #(nop) ADD file:f755805244a649ecca 198.6 MB

[root@docker02 ~]# docker run -it myos 可以新开一个容器myos
[root@48e2452371aa /]# ifconfig 我们刚才在centos上安装的命令都能使用!
[root@48e2452371aa /]# history 之前在centos上的安装软件的历史命令都能看到!
1 ls
2 cd /etc/yum.repos.d
3 rm -rf *
4 vi centos.repo
5 yum clean all
6 yum repolist
7 yum -y install net-tools iproute psmisc vim-enhanced
8 ifconfig
9 exit
10 ifconfig
11 vim
12 history


这个时候我们也可以删除centos!因为centos里有的东西,我们新建的镜像myos都有!
#############################################################################

[root@docker02 ~]# mkdir abc
[root@docker02 ~]# cd abc/
[root@docker02 abc]# touch Dockerfile

[root@docker02 abc]# vim Dockerfile
FROM centos:latest
RUN rm -rf /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/local.repo
RUN yum -y install net-tools iproute psmisc vim-enhanced

[root@docker02 abc]# vim local.repo
[centos]
name=centos7
baseurl=ftp://192.168.3.254/CentOS7
enabled=1
gpgcheck=0

[root@docker02 abc]# ls
Dockerfile local.repo

[root@docker02 abc]# docker build -t abc:latest . 在当前目录下(.代表当前目录)新建一个容器
显示如下:(包含有在容器里执行相应命令的输出显示)
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM centos:latest 这就是我们在文件Dockerfile里写的第1行的命令
---> e934aafc2206
Step 2 : RUN rm -rf /etc/yum.repos.d/* 这就是我们在文件Dockerfile里写的第2行的命令
---> Running in 20e8d29e4ba2
---> e46790c89ab9
Removing intermediate container 20e8d29e4ba2
Step 3 : ADD local.repo /etc/yum.repos.d/local.repo 这就是我们在文件Dockerfile里写的第3行的命令
---> 238a579787fd
Removing intermediate container ce68d2373f3a
Step 4 : RUN yum -y install net-tools iproute psmisc vim-enhanced 这就是我们在文件Dockerfile里写的第4行的命令
---> Running in 2ca79dfe1c83
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
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 centos 651 k
net-tools x86_64 2.0-0.22.20131004git.el7 centos 305 k
psmisc x86_64 22.20-15.el7 centos 141 k
vim-enhanced x86_64 2:7.4.160-2.el7 centos 1.0 M
Installing for dependencies:
gpm-libs x86_64 1.20.7-5.el7 centos 32 k
groff-base x86_64 1.22.2-8.el7 centos 942 k
iptables x86_64 1.4.21-18.0.1.el7.centos centos 428 k
libmnl x86_64 1.0.3-7.el7 centos 23 k
libnetfilter_conntrack x86_64 1.0.6-1.el7_3 centos 55 k
libnfnetlink x86_64 1.0.1-4.el7 centos 26 k
perl x86_64 4:5.16.3-292.el7 centos 8.0 M
perl-Carp noarch 1.26-244.el7 centos 19 k
perl-Encode x86_64 2.51-7.el7 centos 1.5 M
perl-Exporter noarch 5.68-3.el7 centos 28 k
perl-File-Path noarch 2.09-2.el7 centos 26 k
perl-File-Temp noarch 0.23.01-3.el7 centos 56 k
perl-Filter x86_64 1.49-3.el7 centos 76 k
perl-Getopt-Long noarch 2.40-2.el7 centos 56 k
perl-HTTP-Tiny noarch 0.033-3.el7 centos 38 k
perl-PathTools x86_64 3.40-5.el7 centos 82 k
perl-Pod-Escapes noarch 1:1.04-292.el7 centos 51 k
perl-Pod-Perldoc noarch 3.20-4.el7 centos 87 k
perl-Pod-Simple noarch 1:3.28-4.el7 centos 216 k
perl-Pod-Usage noarch 1.63-3.el7 centos 27 k
perl-Scalar-List-Utils x86_64 1.27-248.el7 centos 36 k
perl-Socket x86_64 2.010-4.el7 centos 49 k
perl-Storable x86_64 2.45-3.el7 centos 77 k
perl-Text-ParseWords noarch 3.29-4.el7 centos 14 k
perl-Time-HiRes x86_64 4:1.9725-3.el7 centos 45 k
perl-Time-Local noarch 1.2300-2.el7 centos 24 k
perl-constant noarch 1.27-2.el7 centos 19 k
perl-libs x86_64 4:5.16.3-292.el7 centos 688 k
perl-macros x86_64 4:5.16.3-292.el7 centos 43 k
perl-parent noarch 1:0.225-244.el7 centos 12 k
perl-podlators noarch 2.5.1-3.el7 centos 112 k
perl-threads x86_64 1.87-4.el7 centos 49 k
perl-threads-shared x86_64 1.43-6.el7 centos 39 k
vim-common x86_64 2:7.4.160-2.el7 centos 5.9 M
vim-filesystem x86_64 2:7.4.160-2.el7 centos 9.8 k
which x86_64 2.20-7.el7 centos 41 k

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

Total download size: 21 M
Installed size: 67 M
Downloading packages:
--------------------------------------------------------------------------------
Total 106 MB/s | 21 MB 00:00
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!
---> 269fe0184c81
Removing intermediate container 2ca79dfe1c83
Successfully built 269fe0184c81
到这里就安装成功了!
##############################################################################################
[root@docker02 abc]# docker run -it abc
[root@f4c9fcb9b49c /]# yum repolist
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
repo id repo name status
centos centos7 9591
repolist: 9591
[root@f4c9fcb9b49c /]# 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 8 bytes 648 (648.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 648 (648.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

[root@f4c9fcb9b49c /]# pstree -p
bash(1)---pstree(17)
[root@f4c9fcb9b49c /]# 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
72: eth0@if73: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.2/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:2/64 scope link
valid_lft forever preferred_lft forever
[root@f4c9fcb9b49c /]# exit
exit
[root@docker02 abc]#
############################################################################################################
用脚本创造镜像能启动htppd并修改默认首页

[root@docker02 ~]# docker run -it myos:latest
[root@599d6f58756a /]# yum -y install httpd
[root@599d6f58756a html]# echo "hello httpd" > /var/www/html/index.html

[root@599d6f58756a html]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target


[root@599d6f58756a html]# cat /etc/sysconfig/httpd
#
# This file can be used to set additional environment variables for
# the httpd process, or pass additional options to the httpd
# executable.
#
# Note: With previous versions of httpd, the MPM could be changed by
# editing an "HTTPD" variable here. With the current version, that
# variable is now ignored. The MPM is a loadable module, and the
# choice of MPM can be changed by editing the configuration file
# /etc/httpd/conf.modules.d/00-mpm.conf.
#

#
# To pass additional options (for instance, -D definitions) to the
# httpd binary at startup, set OPTIONS here.
#
#OPTIONS=

#
# This setting ensures the httpd process is started in the "C" locale
# by default. (Some modules will not behave correctly if
# case-sensitive string comparisons are performed in a different
# locale.)
#
LANG=C
###################################################################################################
放综括号[ ]里,就是数组,哪怕里面只有一个数


虚拟机docker02
# vim /etc/docker/daemon.json 自己手写下面3行
{
"insecure-registries":["192.168.3.31:5000"] 其中3.31是本机(又称宿主机)的IP地址
}

[root@docker02 ~]# docker rm $(docker stop $(docker ps -qa)) 先关闭当前的容器并删除
9ecbcce8515c
... ...

[root@docker02 ~]# systemctl restart docker
[root@docker02 ~]# docker run -d -p 5000:5000 registry
Unable to find image 'registry:latest' locally
latest: Pulling from library/registry

456f9d0bf1d1: Pull complete
b7f3f37a05d2: Pull complete
d1b2fc1a6bc7: Pull complete
400c20544fd6: Pull complete
48473a72399c: Pull complete
Digest: sha256:2a5b47a613fd7e9d28120fa77016554c3dffa8913b6a314ede518447ddc68e2f
Status: Downloaded newer image for registry:latest
c37d46ca953e5940739e588c6342f44bd5ebecc95b89be74ccf68769fadc3c71


在另一台虚拟机docker01上查看
[root@docker01 ~]# curl 192.168.3.31:5000/v2/
{}[root@docker01 ~]#


虚拟机docker02
[root@docker02 ~]# docker tag busybox:latest 192.168.3.31:5000/busybox:latest
[root@docker02 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
abc latest 269fe0184c81 4 hours ago 313.8 MB
myos latest 99b9412c6de2 4 hours ago 313.8 MB
registry latest 9c1f09fe9a86 25 hours ago 33.29 MB
busybox latest 59788edf1f3e 11 weeks ago 1.154 MB
192.168.3.31:5000/busybox latest 59788edf1f3e 11 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 7 months ago 79.62 MB
centos latest e934aafc2206 8 months ago 198.6 MB
nginx latest a5311a310510 2 years ago 181.4 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB

[root@docker02 ~]# docker push 192.168.3.31:5000/busybox:latest
The push refers to a repository [192.168.3.31:5000/busybox]
8a788232037e: Pushed
latest: digest: sha256:e6565c8273423e967c96b5178139e95bee4bd6564700948bb756921c916b4fbe size: 527

虚拟机docker02
[root@docker02 ~]# scp /etc/docker/daemon.json 192.168.3.30:/etc/docker/
[root@docker01 ~]# systemctl restart docker
[root@docker01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE

[root@docker01 ~]# docker run -it 192.168.3.31:5000/busybox:latest /bin/bash 直接启动

[root@docker01 ~]# docker images 可以查看到镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.3.31:5000/busybox latest 59788edf1f3e 11 weeks ago 1.154 MB
############################################################################################
[root@9ecbcce8515c /]# cat /etc/httpd/conf/httpd.conf | grep ServerName
# ServerName gives the name and port that the server uses to identify itself.
#ServerName www.example.com:80


############################################################################################
虚拟机docker01

[root@docker01 ~]# docker ps -qa 查看所有的容器
6a169e503f80
... ....

[root@docker01 ~]# docker rm $(docker stop $(docker ps -qa)) 删除所有的容器
6a169e503f80
... ....

[root@docker01 ~]# docker images 查看当前所有镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 59788edf1f3e 11 weeks ago 1.154 MB
ubuntu latest 452a96d81c30 7 months ago 79.62 MB
centos latest e934aafc2206 8 months ago 198.6 MB
registry latest d1fd7d86a825 11 months ago 33.26 MB
nginx latest a5311a310510 2 years ago 181.4 MB
redis latest 1aa84b1b434e 2 years ago 182.8 MB

[root@docker01 ~]# docker images -qa 查看当前所有镜像的ID
59788edf1f3e
... ....

[root@docker01 ~]# for i in `docker images -qa` ; do docker rmi $i ;done 写个for循环,删除查询到的全部镜像
Untagged: ubuntu:latest
Deleted: sha256:452a96d81c30a1e426bc250428263ac9ca3f47c9bf086f876d11cb39cf57aeec
Deleted: sha256:96fccbf869d3c0ee0fb2e976fdf356dc5872f6410030fd094bbc5b34a7559cdb
Deleted: sha256:38ffa1479cb9fd81d0d4d057c282a155a4a83bff5d2b507ee9563f996d74272d
Deleted: sha256:cc6967c5525a55626688a773e4fe578321a2e126a3b1df1bc0763cfd1583c50c
Deleted: sha256:2a2d486f02032f5a6cc56290a244512daa07a8efe0124bccc5701f0a778aa947
Deleted: sha256:65bdd50ee76a485049a2d3c2e92438ac379348e7b576783669dac6f604f6241b
... ....

[root@docker01 ~]# docker images 可以看到当前所有镜像,目前为空,说明已经删除成功
REPOSITORY TAG IMAGE ID CREATED SIZE


可以查看得到刚才新建立的标签192.168.3.31:5000/busybox:latest,说明已经上传成功
[root@docker02 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
abc latest 269fe0184c81 4 hours ago 313.8 MB
myos latest 99b9412c6de2 4 hours ago 313.8 MB
busybox latest 59788edf1f3e 11 weeks ago 1.154 MB
192.168.3.31:5000/busybox latest 59788edf1f3e 11 weeks ago 1.154 MB
... ...


写给for循环,给镜像abc:latest和myos:latest打标签,并上传到私有镜像仓库
[root@docker02 ~]# for i in abc myos ; do docker tag $i:latest 192.168.3.31:5000/$i:latest ; docker push 192.168.3.31:5000/$i:latest ;done
显示如下:
The push refers to a repository [192.168.3.31:5000/abc]
a43f898ee415: Pushed
638faa12d218: Pushed
8be4a38770d9: Pushed
43e653f84b79: Pushed
latest: digest: sha256:f374cc00386b015327bfc83610b80afe9b411a276d383759f200f5872b72c92f size: 1155
The push refers to a repository [192.168.3.31:5000/myos]
5cfb320264fc: Pushed
43e653f84b79: Mounted from abc
latest: digest: sha256:f549361e8c724ea54f47517129b32bd3bcac1b59332ac9dd7f58d159527640a4 size: 741

可以查看得到刚才新建立的标签,说明已经上传成功
[root@docker02 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.3.31:5000/abc latest 269fe0184c81 4 hours ago 313.8 MB
192.168.3.31:5000/myos latest 99b9412c6de2 5 hours ago 313.8 MB
192.168.3.31:5000/busybox latest 59788edf1f3e 11 weeks ago 1.154 MB
... ...


虚拟机docker02
[root@docker01 ~]# curl http://192.168.3.31:5000/v2/_catalog
{"repositories":["abc","busybox","myos"]}
[root@docker01 ~]# curl http://192.168.3.31:5000/v2/busybox/tags/list
{"name":"busybox","tags":["latest"]}
[root@docker01 ~]# curl http://192.168.3.31:5000/v2/myos/tags/list
{"name":"myos","tags":["latest"]}

################################################################################################

[root@docker02 ~]# mkdir /var/webroot
[root@docker02 ~]# echo "webroot" > /var/webroot/index.html
[root@docker02 ~]# ls /var/webroot/
index.html


[root@docker02 ~]# docker run -it -v /var/webroot/:/root/ 192.168.3.31:5000/abc:latest /bin/bash
bash-4.2# ls
anaconda-post.log dev home lib64 mnt proc run srv tmp var
bin etc lib media opt root sbin sys usr
bash-4.2# ls /root/
index.html
bash-4.2# cat /root/index.html
webroot
bash-4.2# cd /root/
bash-4.2# touch f{0..3}
bash-4.2# ls
f0 f1 f2 f3 index.html
bash-4.2# ls /root/
f0 f1 f2 f3 index.html
bash-4.2# exit
exit

[root@docker02 ~]# ls /var/webroot/
f0 f1 f2 f3 index.html

####################################################################################
虚拟机docker01

[root@docker02 ~]# yum -y install nfs-utils
[root@docker02 ~]# mkdir /content
[root@docker02 ~]# vim /etc/exports
/content *(rw,no_root_squash)

[root@docker02 ~]# systemctl restart nfs-server nfs-secure
[root@docker02 ~]# exportfs -rv
exporting *:/content
[root@docker02 ~]# chmod 777 /content
[root@docker02 ~]# echo docker02 > /content/index.html
[root@docker02 ~]# echo 2 > /content/index.html


虚拟机docker02

[root@docker01 ~]# yum -y install nfs-utils
[root@docker01 ~]# systemctl restart nfs-server
[root@docker01 ~]# showmount -e 192.168.3.31
Export list for 192.168.3.31:
/content *
[root@docker01 ~]# mkdir /mnt/aa
[root@docker01 ~]# mount -t nfs 192.168.3.31:/content /mnt/aa
[root@docker01 ~]# ls /mnt/aa
index.html
[root@docker01 ~]# cat /mnt/aa/index.html
2
##############################################################################################
虚拟机docker02

[root@docker02 ~]# docker network create --subnet 10.10.10.0/24 docker1
743d17fb226e315a6b48bf1528db534ebb98099a3de7580efd4e3a86953c9e2c

[root@docker02 ~]# ifconfig
br-743d17fb226e: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 10.10.10.1 netmask 255.255.255.0 broadcast 0.0.0.0
ether 02:42:50:4b:3c:57 txqueuelen 0 (Ethernet)
RX packets 19 bytes 3596 (3.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 19 bytes 3596 (3.5 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:f0ff:fee7:d5a2 prefixlen 64 scopeid 0x20<link>
ether 02:42:f0:e7:d5:a2 txqueuelen 0 (Ethernet)
RX packets 19289 bytes 112016798 (106.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24337 bytes 371368794 (354.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


[root@docker02 ~]# docker run -itd myos
df06c832b263cc38a1ad85013ba11b1439eeba84d3cab760156bf3cf42e52b72

[root@docker02 ~]# docker run -itd myos
c034b056e6b41838b1c44f22e6c35806fceeb838f2ea311de3b64db97f7c9b5a

[root@docker02 ~]# docker run --network=docker1 -itd myos
9ecbe46010f8343606167df2d0965e43eef8b11695dbe969d6ba6e2579ac8b1a

[root@docker02 ~]# docker run --network=docker1 -itd myos
5fa24c1555ece3135c8d2659c59c17128965c3049b9db843b486b9bae9105415


[root@docker02 ~]# docker inspect -f '{{.NetworkSettings.IPAddress}}' d
172.17.0.3

[root@docker02 ~]# docker inspect -f '{{.NetworkSettings.IPAddress}}' c0
172.17.0.4

[root@docker02 ~]# docker inspect 9e
"IPAddress": "10.10.10.2",

[root@docker02 ~]# docker inspect 5
"IPAddress": "10.10.10.3",

[root@docker02 ~]# docker exec -it df bash
[root@df06c832b263 /]# 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

[root@df06c832b263 /]# ping 172.17.0.4 可以ping通
PING 172.17.0.4 (172.17.0.4) 56(84) bytes of data.
64 bytes from 172.17.0.4: icmp_seq=1 ttl=64 time=0.170 ms

[root@df06c832b263 /]# ping 10.10.10.2 不能ping通,当死在这里。ctrl+c停止ping
PING 10.10.10.2 (10.10.10.2) 56(84) bytes of data.

[root@9ecbe46010f8 /]# exit
exit

[root@docker02 ~]# docker exec -it 9e bash
[root@9ecbe46010f8 /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.10.2 netmask 255.255.255.0 broadcast 0.0.0.0

[root@9ecbe46010f8 /]# ping 10.10.10.3
PING 10.10.10.3 (10.10.10.3) 56(84) bytes of data.
64 bytes from 10.10.10.3: icmp_seq=1 ttl=64 time=0.140 ms

[root@9ecbe46010f8 /]# ping 172.17.0.3 不能ping通,当死在这里。ctrl+c停止ping
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.

[root@9ecbe46010f8 /]# exit
exit
#############################################################################################
绑定真机的端口80和nginx的80端口!

[root@docker02 ~]# docker run -p 80:80 -id nginx
a101f5ebe4940130031a9d1c585b4d7dd0d7f5ebd00cac38d795fb2ef7288c6e

真机访问就可以访问得到页面
firefox http://192.168.3.31
显示如下:
Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.
#############################################################################################
绑定真机的端口80和httpd的80端口

[root@docker02 ~]# docker run -p 80:80 -id httpd
9a216e0c4593c4471ec6362558456e3b4228848745d08f316fcb3a9248c73d2d

真机访问就可以访问得到httpd的默认页面
firefox http://192.168.3.31
显示如下:
It works!

 

转载于:https://www.cnblogs.com/summer2/p/10798444.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值