docker筆記14-Dockerfile案例-自定義mycentos
Base映象(scratch)
Docker Hub中99%的映象是透過在base映象中安裝和配置需要的軟體構建出來的。也就是說base映象是所有其他映象的鼻祖。
hub預設centos映象是什麼情況
[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
自定義映象mycentos
1、編寫Dokcerfile檔案
[root@t-docker mycentos]# cat Dockerfile FROM centos MAINTAINER chenzx chenzx@11.com ENV MYPATH /usr/local 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
2、構建
語法:docker build -t 新映象名字:TAG .
[root@t-docker mycentos]# docker build -f ./Dockerfile -t mycentos:1.3 . Sending build context to Docker daemon 2.048kB Step 1/10 : FROM centos ---> 5182e96772bf Step 2/10 : MAINTAINER chenzx chenzx@11.com ---> Running in bf692c9a8f30 Removing intermediate container bf692c9a8f30 ---> be7c6d72dcf6 Step 3/10 : ENV MYPATH /usr/local ---> Running in bfbe973063c4 Removing intermediate container bfbe973063c4 ---> b6117be61d21 Step 4/10 : WORKDIR $MYPATH ---> Running in dc207977e37e Removing intermediate container dc207977e37e ---> a299de1b142d Step 5/10 : RUN yum -y install vim ---> Running in 7b18a2ea02ba Loaded plugins: fastestmirror, ovl Determining fastest mirrors * base: mirror.bit.edu.cn * extras: mirror.bit.edu.cn * updates: mirror.bit.edu.cn Resolving 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 ---> 41b54eafc062 Step 6/10 : RUN yum -y install net-tools ---> Running in 4fe95a3f928d Loaded plugins: fastestmirror, ovl Loading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirror.bit.edu.cn * updates: mirror.bit.edu.cn Resolving Dependencies --> Running transaction check Step 7/10 : EXPOSE 80 ---> Running in b49331f041a0 Removing intermediate container b49331f041a0 ---> 255ce503616b Step 8/10 : CMD echo $MYPATH ---> Running in 0c8a45aa210f Removing intermediate container 0c8a45aa210f ---> b70d750b50c6 Step 9/10 : CMD echo "success-----ok" ---> Running in 0f82aaeab3af Removing intermediate container 0f82aaeab3af ---> 41680031171e Step 10/10 : CMD /bin/bash ---> Running in 5694bd9a1dab Removing intermediate container 5694bd9a1dab ---> 0c868c56748b Successfully built 0c868c56748b Successfully tagged mycentos:1.3 [root@t-docker mycentos]#
[root@t-docker mycentos]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mycentos 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 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@28ab180a72d7 local]#
4、列出映象的變更歷史
功能:從底下往上看,可以看出製作mycentos映象的歷史過程。
[root@t-docker mycentos]# docker images mycentos REPOSITORY TAG IMAGE ID CREATED SIZE mycentos 1.3 0c868c56748b 12 minutes ago 442MB [root@t-docker mycentos]# docker history 0c868c56748b IMAGE CREATED CREATED BY SIZE COMMENT 0c868c56748b 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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28916011/viewspace-2213388/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- docker筆記17-Dockerfile案例-自定義tomcat映象Docker筆記Tomcat
- docker 筆記(基本概念、快速執行、自定義映象)Docker筆記
- docker筆記16-Dockerfile案例-ONBUILD命令案例Docker筆記UI
- STREAMS筆記(8) rule - 自定義筆記
- docker筆記15-Dockerfile案例-CMD、ENTRYPOINT案例Docker筆記
- docker筆記35-資源指標API及自定義指標APIDocker筆記指標API
- docker筆記18-案例-安裝mysqlDocker筆記MySql
- C語言筆記——自定義型別C語言筆記型別
- dojo使用筆記: 自定義ConfirmDialog筆記
- iOS學習筆記--PresentedVC自定義彈窗iOS筆記
- 筆記3:自定義註解的實現筆記
- Java學習筆記之自定義異常Java筆記
- docker官方mysql映象自定義配置DockerMySql
- Pytest學習筆記6-自定義標記mark筆記
- 《Haskell趣學指南》筆記之自定義型別Haskell筆記型別
- 筆記:Docker筆記Docker
- Docker筆記Docker筆記
- docker 筆記Docker筆記
- 集合框架-去重自定義物件案例框架物件
- 玩轉docker之自定義PHP容器DockerPHP
- 中介軟體自定義檢測 JWT 並通過自定義異常丟擲錯誤--筆記JWT筆記
- html頁面自定義文字水印效果案例HTML
- docker使用筆記Docker筆記
- docker 筆記4Docker筆記
- docker 筆記2Docker筆記
- Docker Stack 筆記Docker筆記
- docker筆記(一)Docker筆記
- spark2.4.3 sparkSQL 使用者自定義函式筆記SparkSQL函式筆記
- ios開發筆記--狀態列的自定義,隱藏iOS筆記
- docker Redis 自定義配置檔案啟動DockerRedis
- Docker自定義映象上傳阿里雲Docker阿里
- SQL優化案例-自定義函式索引(五)SQL優化函式索引
- Oracle優化案例-自定義函式索引(五)Oracle優化函式索引
- FineUIMvc隨筆(4)自定義回發引數與自定義回發UIMVC
- Laravel學習筆記之Artisan命令生成自定義模板的方法Laravel筆記
- Android開發筆記(一百二十四)自定義相簿Android筆記
- ASP.NET MVC 學習筆記-7.自定義配置資訊ASP.NETMVC筆記
- iOS開發筆記 | 自定義具有內邊距的labeliOS筆記