1.自定义一个Dockerfile
FROM centos // 继承本地centos的镜像
MAINTAINER zzyyzzyy167@126.com // 作者和邮箱
ENV MYPATH /usr/local
WORKDIR $MYPATH //引用地址,为登录后的落脚点
RUN yum -y install vim //原版的centos镜像中没有vim和 netwok模块
RUN yum -y install net-tools
EXPOSE 80 //暴露端口
CMD echo $MYPATH
CMD echo “success——-…..——ok”
CMD /bin/bash
2.安装过程:
安装 vim和net-tools模块消耗的时间多一些
[root@test mydocker]# docker build -f Dockerfile1 -t mycentos:1.1 .
Sending build context to Docker daemon 3.072kB
Step 1/8 : FROM centos
---> 300e315adb2f
Step 2/8 : MAINTAINER zhy<123@qq.com>
---> Using cache
---> 5ce63c157e9a
Step 3/8 : ENV MYPATH /usr/local
---> Using cache
---> 27bda98124bf
Step 4/8 : WORKDIR $MYPATH
---> Using cache
---> 2cb99337c3af
Step 5/8 : RUN yum -y install vim
---> Running in 9268967cb2bb
CentOS Linux 8 - AppStream 382 kB/s | 6.3 MB 00:16
CentOS Linux 8 - BaseOS 373 kB/s | 2.3 MB 00:06
CentOS Linux 8 - Extras 12 kB/s | 8.6 kB 00:00
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
vim-enhanced x86_64 2:8.0.1763-15.el8 appstream 1.4 M
Installing dependencies:
gpm-libs x86_64 1.20.7-15.el8 appstream 39 k
vim-common x86_64 2:8.0.1763-15.el8 appstream 6.3 M
vim-filesystem noarch 2:8.0.1763-15.el8 appstream 48 k
which x86_64 2.21-12.el8 baseos 49 k
Transaction Summary
================================================================================
Install 5 Packages
Total download size: 7.8 M
Installed size: 30 M
Downloading Packages:
(1/5): gpm-libs-1.20.7-15.el8.x86_64.rpm 238 kB/s | 39 kB 00:00
(2/5): vim-filesystem-8.0.1763-15.el8.noarch.rp 576 kB/s | 48 kB 00:00
(3/5): which-2.21-12.el8.x86_64.rpm 26 kB/s | 49 kB 00:01
(4/5): vim-enhanced-8.0.1763-15.el8.x86_64.rpm 309 kB/s | 1.4 MB 00:04
(5/5): vim-common-8.0.1763-15.el8.x86_64.rpm 194 kB/s | 6.3 MB 00:33
--------------------------------------------------------------------------------
Total 222 kB/s | 7.8 MB 00:36
warning: /var/cache/dnf/appstream-02e86d1c976ab532/packages/gpm-libs-1.20.7-15.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS Linux 8 - AppStream 206 kB/s | 1.6 kB 00:00
Importing GPG key 0x8483C65D:
Userid : "CentOS (CentOS Official Signing Key) <security@centos.org>"
Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : which-2.21-12.el8.x86_64 1/5
Installing : vim-filesystem-2:8.0.1763-15.el8.noarch 2/5
Installing : vim-common-2:8.0.1763-15.el8.x86_64 3/5
Installing : gpm-libs-1.20.7-15.el8.x86_64 4/5
Running scriptlet: gpm-libs-1.20.7-15.el8.x86_64 4/5
Installing : vim-enhanced-2:8.0.1763-15.el8.x86_64 5/5
Running scriptlet: vim-enhanced-2:8.0.1763-15.el8.x86_64 5/5
Running scriptlet: vim-common-2:8.0.1763-15.el8.x86_64 5/5
Verifying : gpm-libs-1.20.7-15.el8.x86_64 1/5
Verifying : vim-common-2:8.0.1763-15.el8.x86_64 2/5
Verifying : vim-enhanced-2:8.0.1763-15.el8.x86_64 3/5
Verifying : vim-filesystem-2:8.0.1763-15.el8.noarch 4/5
Verifying : which-2.21-12.el8.x86_64 5/5
Installed:
gpm-libs-1.20.7-15.el8.x86_64 vim-common-2:8.0.1763-15.el8.x86_64
vim-enhanced-2:8.0.1763-15.el8.x86_64 vim-filesystem-2:8.0.1763-15.el8.noarch
which-2.21-12.el8.x86_64
Complete!
Removing intermediate container 9268967cb2bb
---> f4e0ad28a3c5
Step 6/8 : RUN yum -y install net-tools
---> Running in f5d010858c79
Last metadata expiration check: 0:00:49 ago on Sun Jan 24 08:45:54 2021.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
net-tools x86_64 2.0-0.52.20160912git.el8 baseos 322 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 322 k
Installed size: 942 k
Downloading Packages:
net-tools-2.0-0.52.20160912git.el8.x86_64.rpm 117 kB/s | 322 kB 00:02
--------------------------------------------------------------------------------
Total 96 kB/s | 322 kB 00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : net-tools-2.0-0.52.20160912git.el8.x86_64 1/1
Running scriptlet: net-tools-2.0-0.52.20160912git.el8.x86_64 1/1
Verifying : net-tools-2.0-0.52.20160912git.el8.x86_64 1/1
Installed:
net-tools-2.0-0.52.20160912git.el8.x86_64
Complete!
Removing intermediate container f5d010858c79
---> 17045c410a3a
Step 7/8 : EXPOSE 80
---> Running in e0f8613d2f81
Removing intermediate container e0f8613d2f81
---> 62a690413282
Step 8/8 : CMD /bin/bash
---> Running in f385e8bf4b9c
Removing intermediate container f385e8bf4b9c
---> ee45963ddcf4
Successfully built ee45963ddcf4
Successfully tagged mycentos:1.1
3.启动自定义的镜像
[root@test mydocker]# docker run -it mycentos:1.1
[root@b825aedfbad4 local]# //落脚点为dockerfile中编辑的 /usr/local
[root@b825aedfbad4 local]# vim 1.txt //支持 vim编辑
[root@b825aedfbad4 local]# ip addr //支持 net-tools网络模块
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
10: eth0@if11: <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@b825aedfbad4 local]#
4.查看镜像的变更历史
[root@b825aedfbad4 local]# [root@test mydocker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentos 1.1 ee45963ddcf4 5 hours ago 291MB
[root@test mydocker]# docker history ee45963ddcf4
IMAGE CREATED CREATED BY SIZE COMMENT
ee45963ddcf4 5 hours ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "/bin… 0B
62a690413282 5 hours ago /bin/sh -c #(nop) EXPOSE 80 0B
17045c410a3a 5 hours ago /bin/sh -c yum -y install net-tools 23.3MB
f4e0ad28a3c5 5 hours ago /bin/sh -c yum -y install vim 58.1MB
2cb99337c3af 5 hours ago /bin/sh -c #(nop) WORKDIR /usr/local 0B
27bda98124bf 5 hours ago /bin/sh -c #(nop) ENV MYPATH=/usr/local 0B
5ce63c157e9a 5 hours ago /bin/sh -c #(nop) MAINTAINER zhy<123@qq.com> 0B
300e315adb2f 6 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 6 weeks ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> 6 weeks ago /bin/sh -c #(nop) ADD file:bd7a2aed6ede423b7… 209MB