—> Package iproute.x86_64 0:4.11.0-30.el7 will be installed
–> Processing Dependency: libmnl.so.0(LIBMNL_1.0)(64bit) for package: iproute-4.11.0-30.el7.x86_64
–> Processing Dependency: libxtables.so.10()(64bit) for package: iproute-4.11.0-30.el7.x86_64
–> Processing Dependency: libmnl.so.0()(64bit) for package: iproute-4.11.0-30.el7.x86_64
–> Running transaction check
—> Package iptables.x86_64 0:1.4.21-35.el7 will be installed
–> Processing Dependency: libnfnetlink.so.0()(64bit) for package: iptables-1.4.21-35.el7.x86_64
–> Processing Dependency: libnetfilter_conntrack.so.3()(64bit) for package: iptables-1.4.21-35.el7.x86_64
—> Package libmnl.x86_64 0:1.0.3-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
–> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
iproute x86_64 4.11.0-30.el7 base 805 k
Installing for dependencies:
iptables x86_64 1.4.21-35.el7 base 432 k
libmnl x86_64 1.0.3-7.el7 base 23 k
libnetfilter_conntrack x86_64 1.0.6-1.el7_3 base 55 k
libnfnetlink x86_64 1.0.1-4.el7 base 26 k
Transaction Summary
================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 1.3 M
Installed size: 3.5 M
Downloading packages:
Total 1.8 MB/s | 1.3 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libmnl-1.0.3-7.el7.x86_64 1/5
Installing : libnfnetlink-1.0.1-4.el7.x86_64 2/5
Installing : libnetfilter_conntrack-1.0.6-1.el7_3.x86_64 3/5
Installing : iptables-1.4.21-35.el7.x86_64 4/5
Installing : iproute-4.11.0-30.el7.x86_64 5/5
Verifying : libnfnetlink-1.0.1-4.el7.x86_64 1/5
Verifying : libnetfilter_conntrack-1.0.6-1.el7_3.x86_64 2/5
Verifying : iptables-1.4.21-35.el7.x86_64 3/5
Verifying : libmnl-1.0.3-7.el7.x86_64 4/5
Verifying : iproute-4.11.0-30.el7.x86_64 5/5
Installed:
iproute.x86_64 0:4.11.0-30.el7
Dependency Installed:
iptables.x86_64 0:1.4.21-35.el7
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
Complete!
Removing intermediate container 69691bc80819
—> 443471b80ff2
Step 5/5 : CMD [“/bin/bash”]
—> Running in 7135ecfff344
Removing intermediate container 7135ecfff344
—> 4105c41a4cc1
Successfully built 4105c41a4cc1
Successfully tagged centos:v1
- 编译完成以后可以通过查看镜像看到我们制作的这个镜像了
然后查看详细可以看到 前4项就是我们自定义的内容了
[root@ccx ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos v1 4105c41a4cc1 About a minute ago 433MB
nginx latest d1a364dc548d 3 weeks ago 133MB
hub.c.163.com/library/wordpress latest dccaeccfba36 3 years ago 406MB
hub.c.163.com/library/centos latest 328edcd84f1b 3 years ago 193MB
hub.c.163.com/library/mysql latest 9e64176cd8a2 4 years ago 407MB
[root@ccx ~]#
[root@ccx ~]# docker history centos:v1
IMAGE CREATED CREATED BY SIZE COMMENT
4105c41a4cc1 3 minutes ago /bin/sh -c #(nop) CMD [“/bin/bash”] 0B
443471b80ff2 3 minutes ago /bin/sh -c yum install iproute -y 121MB
652b957f8a8b 3 minutes ago /bin/sh -c yum install net-tools -y 119MB
cf8f1b1f7f64 4 minutes ago /bin/sh -c #(nop) MAINTAINER ccx 0B
328edcd84f1b 3 years ago /bin/sh -c #(nop) CMD [“/bin/bash”] 0B
3 years ago /bin/sh -c #(nop) LABEL name=CentOS Base Im… 0B
3 years ago /bin/sh -c #(nop) ADD file:63492ba809361c51e… 193MB
[root@ccx ~]#
- 现在通过这个镜像生成容器测试
可以看到这个镜像中这2命令确实有了
[root@ccx ~]# docker run -it --rm centos:v1
[root@0508e306c79d /]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
16: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@0508e306c79d /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 6 bytes 516 (516.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
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (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@0508e306c79d /]#
编辑镜像文件【注意事项说明】
-
上面的
Dockerfile
配置文件中,每多写一个RUN
,所生成的镜像都会多一层layer
,这样就会导致生成的镜像很大,所以我们尽可能的只写一个RUN
让这些命令全部实现,所以修改后如下咯。 -
我们可以将Dockerfile文件修改为如下
&&
是与的意思,就是前面执行完了执行后面的命令, \
是换行的意思【后面不能有空格哈】,如果有很多命令需要执行,则加很多 && \
就是了【这样是为了美观】
[root@ccx ~]# cat Dockerfile
FROM hub.c.163.com/library/centos
MAINTAINER ccx
RUN yum install net-tools -y && \
yum install iproute -y
CMD [“/bin/bash”]
[root@ccx ~]#
- 然后我们重新生成一个 centos:v2版本
docker build -t centos:v2 .
过程如下
[root@ccx ~]# docker build -t centos:v2 .
Sending build context to Docker daemon 1.177GB
Step 1/4 : FROM hub.c.163.com/library/centos
—> 328edcd84f1b
Step 2/4 : MAINTAINER ccx
—> Using cache
—> cf8f1b1f7f64
Step 3/4 : RUN yum install net-tools -y && yum install iproute -y
—> Running in 4ed42d93dd76
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
-
base: mirrors.aliyun.com
-
extras: mirrors.aliyun.com
-
updates: mirrors.aliyun.com
Resolving Dependencies
–> Running transaction check
—> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
================================================================================