这篇文章主要为大家展示了“Docker中Dockerfile如何自定义myCentos”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“docker中Dockerfile如何自定义mycentos”
这篇文章主要为大家展示了“Docker中Dockerfile如何自定义myCentos”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“docker中Dockerfile如何自定义mycentos”这篇文章吧。
Docker Hub中99%的镜像是通过在base镜像中安装和配置需要的软件构建出来的。也就是说base镜像是所有其他镜像的鼻祖。
[root@t-docker chenzx]# docker run -it centos[root@ef7873879474 /]# vim a.txt ##默认ceonts不支持vim命令bash: vim: command not found[root@ef7873879474 /]# ifconfig ##默认centos不支持ifconfig命令bash: ifconfig: command not found
1、编写Dokcerfile文件
[root@t-docker mycentos]# cat Dockerfile FROM centosMaiNTAINER chenzx chenzx@11.comENV MYPATH /usr/localWORKDIR $MYPATHRUN yum -y install vimRUN yum -y install net-toolsEXPOSE 80CMD echo $MYPATHCMD echo "success-----ok"CMD /bin/bash
2、构建
语法:docker build -t 新镜像名字:TAG .
[root@t-docker mycentos]# docker build -f ./Dockerfile -t mycentos:1.3 .Sending build context to Docker daemon 2.048kBStep 1/10 : FROM centos ---> 5182e96772bfStep 2/10 : MAINTAINER chenzx chenzx@11.com ---> Running in bf692c9a8f30Removing intermediate container bf692c9a8f30 ---> be7c6d72dcf6Step 3/10 : ENV MYPATH /usr/local ---> Running in bfbe973063c4Removing intermediate container bfbe973063c4 ---> b6117be61d21Step 4/10 : WORKDIR $MYPATH ---> Running in dc207977e37eRemoving intermediate container dc207977e37e ---> a299de1b142dStep 5/10 : RUN yum -y install vim ---> Running in 7b18a2ea02baLoaded plugins: fastestmirror, ovlDetermining fastest mirrors * base: mirror.bit.edu.cn * extras: mirror.bit.edu.cn * updates: mirror.bit.edu.cnResolving Dependencies--> Running transaction check---> Package vim-enhanced.x86_64 2:7.4.160-4.el7 will be installed--> Processing Dependency: vim-common = 2:7.4.160-4.el7 for package: 2:vim-enhanced-7.4.160-4.el7.x86_64--> Processing Dependency: which for package: 2:vim-enhanced-7.4.160-4.el7.x86_64--> Processing Dependency: perl(:MODULE_COMPAT_5.16.3) for package: 2:vim-enhanced-7.4.160-4.el7.x86_64--> Processing Dependency: libperl.so()(64bit) for package: 2:vim-enhanced-7.4.160-4.el7.x86_64 ---> 41b54eafc062Step 6/10 : RUN yum -y install net-tools ---> Running in 4fe95a3f928dLoaded plugins: fastestmirror, ovlLoading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirror.bit.edu.cn * updates: mirror.bit.edu.cnResolving Dependencies--> Running transaction checkStep 7/10 : EXPOSE 80 ---> Running in b49331f041a0Removing intermediate container b49331f041a0 ---> 255ce503616bStep 8/10 : CMD echo $MYPATH ---> Running in 0c8a45aa210fRemoving intermediate container 0c8a45aa210f ---> b70d750b50c6Step 9/10 : CMD echo "success-----ok" ---> Running in 0f82aaeab3afRemoving intermediate container 0f82aaeab3af ---> 41680031171eStep 10/10 : CMD /bin/bash ---> Running in 5694bd9a1dabRemoving intermediate container 5694bd9a1dab ---> 0c868c56748bSuccessfully built 0c868c56748bSuccessfully tagged mycentos:1.3[root@t-docker mycentos]#
[root@t-docker mycentos]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmycentos 1.3 0c868c56748b 5 minutes aGo 442MB
3、运行
[root@t-docker mycentos]# docker run -it mycentos:1.3[root@28ab180a72d7 local]# pwd ##落脚点是/usr/local/usr/local[root@28ab180a72d7 local]# vim a.txt ##vim命令也有了[root@28ab180a72d7 local]# ifconfig ##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 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 0lo: 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@28ab180a72d7 local]#
4、列出镜像的变更历史
功能:从底下往上看,可以看出制作mycentos镜像的历史过程。
[root@t-docker mycentos]# docker images mycentosREPOSITORY TAG IMAGE ID CREATED SIZEmycentos 1.3 0c868c56748b 12 minutes ago 442MB[root@t-docker mycentos]# docker history 0c868c56748bIMAGE CREATED CREATED BY SIZE COMMENT0c868c56748b 12 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "/bin… 0B 41680031171e 12 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo… 0B b70d750b50c6 12 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo… 0B 255ce503616b 12 minutes ago /bin/sh -c #(nop) EXPOSE 80 0B 1cb7e8747969 12 minutes ago /bin/sh -c yum -y install net-tools 93.7MB 41b54eafc062 12 minutes ago /bin/sh -c yum -y install vim 149MB a299de1b142d 13 minutes ago /bin/sh -c #(nop) WORKDIR /usr/local 0B b6117be61d21 13 minutes ago /bin/sh -c #(nop) ENV MYPATH=/usr/local 0B be7c6d72dcf6 13 minutes ago /bin/sh -c #(nop) MAINTAINER chenzx chenzx@… 0B 5182e96772bf 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 3 weeks ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B <missing> 3 weeks ago /bin/sh -c #(nop) ADD file:6340c690b08865d7e… 200MB
以上是“docker中Dockerfile如何自定义mycentos”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网精选频道!
--结束END--
本文标题: docker中Dockerfile如何自定义mycentos
本文链接: https://lsjlt.com/news/238337.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0