#自定义mycentos目的使我们自己的镜像具备如下功能:
1.登录后的默认路径
2.可以使用vim 编辑器
3.能够使用查看网络配置的ifconfig命令
#编写
[[email protected] ~]# cd /mydocker
[[email protected] mydocker]# ll
total 4
-rw-r--r-- 1 root root 137 Jan 12 15:37 Dockerfile
[[email protected] mydocker]# vim Dockerfile2
FROM centos
MAINTAINER zzyy<[email protected]>
ENV MYPATH /tmp
WORKDIR $MYPATH
RUN yum -y install vim
RUN yum -y install net-tools
EXPOSE 80
CMD echo $MYPATH
CMD echo "success---------ok"
CMD /bin/bash
构建 . 表示当前路径
docker buile -t 新镜像名字:TAG .
[[email protected] mydocker]# docker build -f /mydocker/Dockerfile2 -t mycentos:1.2 .
Sending build context to Docker daemon 3.072 kB
Sending build context to Docker daemon
Step 0 : FROM centos
---> ab9a80ab07d0
Step 1 : MAINTAINER zzyy<[email protected]>
---> Using cache
---> 24c272f9f06a
Step 2 : ENV MYPATH /tmp
---> Using cache
---> 9be1b8d910a7
Step 3 : RUN yum -y install vim
---> Running in 30737acef213
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
[[email protected] mydocker]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mycentos 1.2 0bfae97b4d8d 8 minutes ago 351.7 MB
alvin/centos latest d7609a14297c 5 days ago 201.8 MB
atguigu/mytomcat 1.1 4a262f07577c 6 days ago 462.5 MB
centos latest ab9a80ab07d0 6 weeks ago 201.8 MB
[[email protected] mydocker]# docker run -it mycentos:1.2
[[email protected] tmp]# pwd
/tmp
[[email protected] tmp]#
[[email protected] tmp]# vim aa.txt
[[email protected] tmp]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.8 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:8 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:08 txqueuelen 0 (Ethernet)
RX packets 6 bytes 468 (468.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7 bytes 558 (558.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 0 (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] mydocker]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mycentos 1.2 050490e6d28e 5 minutes ago 351.7 MB
alvin/centos latest d7609a14297c 5 days ago 201.8 MB
atguigu/mytomcat 1.1 4a262f07577c 6 days ago 462.5 MB
centos latest ab9a80ab07d0 6 weeks ago 201.8 MB
#查看镜像变更历史
[[email protected] mydocker]# docker history 050490e6d28e
IMAGE CREATED CREATED BY SIZE COMMENT
050490e6d28e 5 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "/bin/b 0 B
74036fef1a9b 5 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo \ 0 B
1f5252525eaf 5 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo $ 0 B
9613661e3069 5 minutes ago /bin/sh -c #(nop) EXPOSE 80/tcp 0 B
fd58c78420e1 5 minutes ago /bin/sh -c yum -y install net-tools 24.17 MB
55357dd693fc 5 minutes ago /bin/sh -c yum -y install vim 125.8 MB
51d9229a4b68 6 minutes ago /bin/sh -c #(nop) WORKDIR /tmp 0 B
8f300b39e4c1 6 minutes ago /bin/sh -c #(nop) ENV MYPATH=/tmp 0 B
c2e8c62e088a 6 minutes ago /bin/sh -c #(nop) MAINTAINER zzyy<[email protected] 0 B
ab9a80ab07d0 6 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
f016d310caa9 6 weeks ago /bin/sh -c #(nop) LABEL org.label-schema.sch 0 B
e4b082fc6cdb 6 weeks ago /bin/sh -c #(nop) ADD file:6f877549795f4798a3 201.8 MB
[[email protected] mydocker]#
原文地址:https://www.cnblogs.com/ahtornado/p/10300019.html