• Dockerfile构建镜像


      Dockerfile构建镜像的步骤:

    1. 从基础镜像运行一个容器
    2. 执行一条指令,对容器做出修改
    3. 执行类似docker commit的操作,提交一个新的镜像层
    4. 再基于刚提交的镜像运行一个新的容器
    5. 执行Dockerfile中的下一条指令,直至所有指令执行完毕

      编写一个简单的Dockerfile文件:

    [root@docker df_test]# vim Dockerfile
    #first dockerfile for test    
    FROM ubuntu:latest
    MAINTAINER fngje "fngje0128@163.com"
    RUN apt-get update
    RUN apt-get install -y nginx
    EXPOSE 80
    View Code

      docker build通过Dockerfile构建镜像:

    [root@docker df_test]# docker build -t="jie/df_test1" .
    Sending build context to Docker daemon  2.048kB
    Step 1/5 : FROM ubuntu:latest
    ---> d355ed3537e9
    Step 2/5 : MAINTAINER fngje "fngje0128@163.com"
    ---> Running in 30b19d64eba7
    ---> e0abbc4c73a2
    Removing intermediate container 30b19d64eba7
    Step 3/5 : RUN apt-get update
    ---> Running in dda28d31a3ff
    Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
    Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
    Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [42.0 kB]
    Get:4 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [380 kB]
    Get:5 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
    Get:6 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
    Get:7 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]
    Ign:4 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages
    Get:8 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.8 kB]
    Get:9 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [178 kB]
    Get:10 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [2931 B]
    Get:4 http://110.96.193.9:81/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [380 kB]
    Ign:7 http://archive.ubuntu.com/ubuntu xenial/universe Sources
    Get:11 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
    Get:11 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
    Get:11 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
    Get:12 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
    Get:13 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
    Get:14 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
    Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [205 kB]
    Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [737 kB]
    Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.2 kB]
    Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [637 kB]
    Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.8 kB]
    Get:20 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [4930 B]
    Get:21 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [6241 B]
    Ign:7 http://110.96.192.10:80/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/archive.ubuntu.com/ubuntu xenial/universe Sources
    Get:7 http://110.96.192.10:80/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/archive.ubuntu.com/ubuntu xenial/universe Sources [7728 kB]
    Fetched 21.2 MB in 24min 10s (14.6 kB/s)
    Reading package lists...
    ---> 16db2d4bc8da
    Removing intermediate container dda28d31a3ff
    Step 4/5 : RUN apt-get install -y nginx
    ---> Running in a643350c251f
    Reading package lists...
    Building dependency tree...
    Reading state information...
    The following additional packages will be installed:
    fontconfig-config fonts-dejavu-core geoip-database libexpat1 libfontconfig1
    libfreetype6 libgd3 libgeoip1 libicu55 libjbig0 libjpeg-turbo8 libjpeg8
    libpng12-0 libssl1.0.0 libtiff5 libvpx3 libx11-6 libx11-data libxau6 libxcb1
    libxdmcp6 libxml2 libxpm4 libxslt1.1 nginx-common nginx-core sgml-base ucf
    xml-core
    Suggested packages:
    libgd-tools geoip-bin fcgiwrap nginx-doc ssl-cert sgml-base-doc debhelper
    The following NEW packages will be installed:
    fontconfig-config fonts-dejavu-core geoip-database libexpat1 libfontconfig1
    libfreetype6 libgd3 libgeoip1 libicu55 libjbig0 libjpeg-turbo8 libjpeg8
    libpng12-0 libssl1.0.0 libtiff5 libvpx3 libx11-6 libx11-data libxau6 libxcb1
    libxdmcp6 libxml2 libxpm4 libxslt1.1 nginx nginx-common nginx-core sgml-base
    ucf xml-core
    0 upgraded, 30 newly installed, 0 to remove and 10 not upgraded.
    Need to get 15.5 MB of archives.
    After this operation, 57.3 MB of additional disk space will be used.
    Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxau6 amd64 1:1.0.8-1 [8376 B]
    Get:2 http://archive.ubuntu.com/ubuntu xenial/main amd64 sgml-base all 1.26+nmu4ubuntu1 [12.5 kB]
    Get:3 http://archive.ubuntu.com/ubuntu xenial/main amd64 libjpeg-turbo8 amd64 1.4.2-0ubuntu3 [111 kB]
    Get:4 http://archive.ubuntu.com/ubuntu xenial/main amd64 libjbig0 amd64 2.1-3.1 [26.6 kB]
    Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libexpat1 amd64 2.1.0-7ubuntu0.16.04.2 [71.3 kB]
    Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 libpng12-0 amd64 1.2.54-1ubuntu1 [116 kB]
    Get:7 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl1.0.0 amd64 1.0.2g-1ubuntu4.8 [1081 kB]
    Get:8 http://archive.ubuntu.com/ubuntu xenial/main amd64 ucf all 3.0036 [52.9 kB]
    Get:9 http://archive.ubuntu.com/ubuntu xenial/main amd64 geoip-database all 20160408-1 [1678 kB]
    Get:10 http://archive.ubuntu.com/ubuntu xenial/main amd64 libgeoip1 amd64 1.6.9-1 [70.1 kB]
    Get:11 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libicu55 amd64 55.1-7ubuntu0.2 [7659 kB]
    Get:12 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxdmcp6 amd64 1:1.1.2-1.1 [11.0 kB]
    Get:13 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxcb1 amd64 1.11.1-1ubuntu1 [40.0 kB]
    Get:14 http://archive.ubuntu.com/ubuntu xenial/main amd64 libx11-data all 2:1.6.3-1ubuntu2 [113 kB]
    Get:15 http://archive.ubuntu.com/ubuntu xenial/main amd64 libx11-6 amd64 2:1.6.3-1ubuntu2 [571 kB]
    Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libxml2 amd64 2.9.3+dfsg1-1ubuntu0.2 [697 kB]
    Get:17 http://archive.ubuntu.com/ubuntu xenial/main amd64 xml-core all 0.13+nmu2 [23.3 kB]
    Get:18 http://archive.ubuntu.com/ubuntu xenial/main amd64 fonts-dejavu-core all 2.35-1 [1039 kB]
    Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 fontconfig-config all 2.11.94-0ubuntu1.1 [49.9 kB]
    Get:20 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libfreetype6 amd64 2.6.1-0.1ubuntu2.3 [316 kB]
    Get:21 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libfontconfig1 amd64 2.11.94-0ubuntu1.1 [131 kB]
    Get:22 http://archive.ubuntu.com/ubuntu xenial/main amd64 libjpeg8 amd64 8c-2ubuntu8 [2194 B]
    Get:23 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libtiff5 amd64 4.0.6-1ubuntu0.2 [146 kB]
    Get:24 http://archive.ubuntu.com/ubuntu xenial/main amd64 libvpx3 amd64 1.5.0-2ubuntu1 [732 kB]
    Get:25 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libxpm4 amd64 1:3.5.11-1ubuntu0.16.04.1 [33.8 kB]
    Get:26 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libgd3 amd64 2.1.1-4ubuntu0.16.04.6 [126 kB]
    Get:27 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libxslt1.1 amd64 1.1.28-2.1ubuntu0.1 [145 kB]
    Get:28 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-common all 1.10.3-0ubuntu0.16.04.2 [26.6 kB]
    Get:29 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-core amd64 1.10.3-0ubuntu0.16.04.2 [428 kB]
    Get:30 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx all 1.10.3-0ubuntu0.16.04.2 [3490 B]
    debconf: delaying package configuration, since apt-utils is not installed
    Fetched 15.5 MB in 3min 50s (67.4 kB/s)
    Selecting previously unselected package libxau6:amd64.
    (Reading database ... 4764 files and directories currently installed.)
    Preparing to unpack .../libxau6_1%3a1.0.8-1_amd64.deb ...
    Unpacking libxau6:amd64 (1:1.0.8-1) ...
    Selecting previously unselected package sgml-base.
    Preparing to unpack .../sgml-base_1.26+nmu4ubuntu1_all.deb ...
    Unpacking sgml-base (1.26+nmu4ubuntu1) ...
    Selecting previously unselected package libjpeg-turbo8:amd64.
    Preparing to unpack .../libjpeg-turbo8_1.4.2-0ubuntu3_amd64.deb ...
    Unpacking libjpeg-turbo8:amd64 (1.4.2-0ubuntu3) ...
    Selecting previously unselected package libjbig0:amd64.
    Preparing to unpack .../libjbig0_2.1-3.1_amd64.deb ...
    Unpacking libjbig0:amd64 (2.1-3.1) ...
    Selecting previously unselected package libexpat1:amd64.
    Preparing to unpack .../libexpat1_2.1.0-7ubuntu0.16.04.2_amd64.deb ...
    Unpacking libexpat1:amd64 (2.1.0-7ubuntu0.16.04.2) ...
    Selecting previously unselected package libpng12-0:amd64.
    Preparing to unpack .../libpng12-0_1.2.54-1ubuntu1_amd64.deb ...
    Unpacking libpng12-0:amd64 (1.2.54-1ubuntu1) ...
    Selecting previously unselected package libssl1.0.0:amd64.
    Preparing to unpack .../libssl1.0.0_1.0.2g-1ubuntu4.8_amd64.deb ...
    Unpacking libssl1.0.0:amd64 (1.0.2g-1ubuntu4.8) ...
    Selecting previously unselected package ucf.
    Preparing to unpack .../archives/ucf_3.0036_all.deb ...
    Moving old data out of the way
    Unpacking ucf (3.0036) ...
    Selecting previously unselected package geoip-database.
    Preparing to unpack .../geoip-database_20160408-1_all.deb ...
    Unpacking geoip-database (20160408-1) ...
    Selecting previously unselected package libgeoip1:amd64.
    Preparing to unpack .../libgeoip1_1.6.9-1_amd64.deb ...
    Unpacking libgeoip1:amd64 (1.6.9-1) ...
    Selecting previously unselected package libicu55:amd64.
    Preparing to unpack .../libicu55_55.1-7ubuntu0.2_amd64.deb ...
    Unpacking libicu55:amd64 (55.1-7ubuntu0.2) ...
    Selecting previously unselected package libxdmcp6:amd64.
    Preparing to unpack .../libxdmcp6_1%3a1.1.2-1.1_amd64.deb ...
    Unpacking libxdmcp6:amd64 (1:1.1.2-1.1) ...
    Selecting previously unselected package libxcb1:amd64.
    Preparing to unpack .../libxcb1_1.11.1-1ubuntu1_amd64.deb ...
    Unpacking libxcb1:amd64 (1.11.1-1ubuntu1) ...
    Selecting previously unselected package libx11-data.
    Preparing to unpack .../libx11-data_2%3a1.6.3-1ubuntu2_all.deb ...
    Unpacking libx11-data (2:1.6.3-1ubuntu2) ...
    Selecting previously unselected package libx11-6:amd64.
    Preparing to unpack .../libx11-6_2%3a1.6.3-1ubuntu2_amd64.deb ...
    Unpacking libx11-6:amd64 (2:1.6.3-1ubuntu2) ...
    Selecting previously unselected package libxml2:amd64.
    Preparing to unpack .../libxml2_2.9.3+dfsg1-1ubuntu0.2_amd64.deb ...
    Unpacking libxml2:amd64 (2.9.3+dfsg1-1ubuntu0.2) ...
    Selecting previously unselected package xml-core.
    Preparing to unpack .../xml-core_0.13+nmu2_all.deb ...
    Unpacking xml-core (0.13+nmu2) ...
    Selecting previously unselected package fonts-dejavu-core.
    Preparing to unpack .../fonts-dejavu-core_2.35-1_all.deb ...
    Unpacking fonts-dejavu-core (2.35-1) ...
    Selecting previously unselected package fontconfig-config.
    Preparing to unpack .../fontconfig-config_2.11.94-0ubuntu1.1_all.deb ...
    Unpacking fontconfig-config (2.11.94-0ubuntu1.1) ...
    Selecting previously unselected package libfreetype6:amd64.
    Preparing to unpack .../libfreetype6_2.6.1-0.1ubuntu2.3_amd64.deb ...
    Unpacking libfreetype6:amd64 (2.6.1-0.1ubuntu2.3) ...
    Selecting previously unselected package libfontconfig1:amd64.
    Preparing to unpack .../libfontconfig1_2.11.94-0ubuntu1.1_amd64.deb ...
    Unpacking libfontconfig1:amd64 (2.11.94-0ubuntu1.1) ...
    Selecting previously unselected package libjpeg8:amd64.
    Preparing to unpack .../libjpeg8_8c-2ubuntu8_amd64.deb ...
    Unpacking libjpeg8:amd64 (8c-2ubuntu8) ...
    Selecting previously unselected package libtiff5:amd64.
    Preparing to unpack .../libtiff5_4.0.6-1ubuntu0.2_amd64.deb ...
    Unpacking libtiff5:amd64 (4.0.6-1ubuntu0.2) ...
    Selecting previously unselected package libvpx3:amd64.
    Preparing to unpack .../libvpx3_1.5.0-2ubuntu1_amd64.deb ...
    Unpacking libvpx3:amd64 (1.5.0-2ubuntu1) ...
    Selecting previously unselected package libxpm4:amd64.
    Preparing to unpack .../libxpm4_1%3a3.5.11-1ubuntu0.16.04.1_amd64.deb ...
    Unpacking libxpm4:amd64 (1:3.5.11-1ubuntu0.16.04.1) ...
    Selecting previously unselected package libgd3:amd64.
    Preparing to unpack .../libgd3_2.1.1-4ubuntu0.16.04.6_amd64.deb ...
    Unpacking libgd3:amd64 (2.1.1-4ubuntu0.16.04.6) ...
    Selecting previously unselected package libxslt1.1:amd64.
    Preparing to unpack .../libxslt1.1_1.1.28-2.1ubuntu0.1_amd64.deb ...
    Unpacking libxslt1.1:amd64 (1.1.28-2.1ubuntu0.1) ...
    Selecting previously unselected package nginx-common.
    Preparing to unpack .../nginx-common_1.10.3-0ubuntu0.16.04.2_all.deb ...
    Unpacking nginx-common (1.10.3-0ubuntu0.16.04.2) ...
    Selecting previously unselected package nginx-core.
    Preparing to unpack .../nginx-core_1.10.3-0ubuntu0.16.04.2_amd64.deb ...
    Unpacking nginx-core (1.10.3-0ubuntu0.16.04.2) ...
    Selecting previously unselected package nginx.
    Preparing to unpack .../nginx_1.10.3-0ubuntu0.16.04.2_all.deb ...
    Unpacking nginx (1.10.3-0ubuntu0.16.04.2) ...
    Processing triggers for libc-bin (2.23-0ubuntu9) ...
    Processing triggers for systemd (229-4ubuntu17) ...
    Setting up libxau6:amd64 (1:1.0.8-1) ...
    Setting up sgml-base (1.26+nmu4ubuntu1) ...
    Setting up libjpeg-turbo8:amd64 (1.4.2-0ubuntu3) ...
    Setting up libjbig0:amd64 (2.1-3.1) ...
    Setting up libexpat1:amd64 (2.1.0-7ubuntu0.16.04.2) ...
    Setting up libpng12-0:amd64 (1.2.54-1ubuntu1) ...
    Setting up libssl1.0.0:amd64 (1.0.2g-1ubuntu4.8) ...
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
    debconf: falling back to frontend: Teletype
    Setting up ucf (3.0036) ...
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
    debconf: falling back to frontend: Teletype
    Setting up geoip-database (20160408-1) ...
    Setting up libgeoip1:amd64 (1.6.9-1) ...
    Setting up libicu55:amd64 (55.1-7ubuntu0.2) ...
    Setting up libxdmcp6:amd64 (1:1.1.2-1.1) ...
    Setting up libxcb1:amd64 (1.11.1-1ubuntu1) ...
    Setting up libx11-data (2:1.6.3-1ubuntu2) ...
    Setting up libx11-6:amd64 (2:1.6.3-1ubuntu2) ...
    Setting up libxml2:amd64 (2.9.3+dfsg1-1ubuntu0.2) ...
    Setting up xml-core (0.13+nmu2) ...
    Setting up fonts-dejavu-core (2.35-1) ...
    Setting up fontconfig-config (2.11.94-0ubuntu1.1) ...
    Setting up libfreetype6:amd64 (2.6.1-0.1ubuntu2.3) ...
    Setting up libfontconfig1:amd64 (2.11.94-0ubuntu1.1) ...
    Setting up libjpeg8:amd64 (8c-2ubuntu8) ...
    Setting up libtiff5:amd64 (4.0.6-1ubuntu0.2) ...
    Setting up libvpx3:amd64 (1.5.0-2ubuntu1) ...
    Setting up libxpm4:amd64 (1:3.5.11-1ubuntu0.16.04.1) ...
    Setting up libgd3:amd64 (2.1.1-4ubuntu0.16.04.6) ...
    Setting up libxslt1.1:amd64 (1.1.28-2.1ubuntu0.1) ...
    Setting up nginx-common (1.10.3-0ubuntu0.16.04.2) ...
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
    debconf: falling back to frontend: Teletype
    Setting up nginx-core (1.10.3-0ubuntu0.16.04.2) ...
    invoke-rc.d: could not determine current runlevel
    invoke-rc.d: policy-rc.d denied execution of start.
    Setting up nginx (1.10.3-0ubuntu0.16.04.2) ...
    Processing triggers for libc-bin (2.23-0ubuntu9) ...
    Processing triggers for sgml-base (1.26+nmu4ubuntu1) ...
    Processing triggers for systemd (229-4ubuntu17) ...
    ---> 70310e80c2a3
    Removing intermediate container a643350c251f
    Step 5/5 : EXPOSE 80
    ---> Running in ffb65e191ab9
    ---> cd7c340503bc
    Removing intermediate container ffb65e191ab9
    Successfully built cd7c340503bc
    Successfully tagged jie/df_test1:latest
    [root@docker df_test]#
    View Code

      构建缓存:

      docker build通过Dockerfile构建镜像的过程中会在基础镜像上层生成生成一个新的镜像,在构建镜像的过程中的输出信息中可以看到对应的镜像ID号,可以方便我们在构建镜像过程中报错时通过这些中间生成的镜像来排错,如果镜像成功构建,则这些中间过程生成的镜像则会被缓存下来,下一次通过该Dockerfile构建镜像的时候就会直接使用这些缓存,构建镜像的速度会很快。

    [root@docker df_test]# docker build -t="jie/df_test" .
    Sending build context to Docker daemon  2.048kB
    Step 1/5 : FROM ubuntu:latest
     ---> d355ed3537e9
    Step 2/5 : MAINTAINER fngje "fngje0128@163.com"
     ---> Using cache
     ---> e0abbc4c73a2
    Step 3/5 : RUN apt-get update
     ---> Using cache
     ---> 16db2d4bc8da
    Step 4/5 : RUN apt-get install -y nginx
     ---> Using cache
     ---> 70310e80c2a3
    Step 5/5 : EXPOSE 80
     ---> Using cache
     ---> cd7c340503bc
    Successfully built cd7c340503bc
    Successfully tagged jie/df_test:latest
    [root@docker df_test]#
    View Code

      不使用构建缓存:

      有时,我们重新构建镜像的时候不希望使用构建缓存,则可以通过docker build 的--no-cache参数。

    [root@docker df_test]# docker build -t="jie/df_test2" . --no-cache
    Sending build context to Docker daemon  2.048kB
    Step 1/5 : FROM ubuntu:latest
    ---> d355ed3537e9
    Step 2/5 : MAINTAINER fngje "fngje0128@163.com"
    ---> Running in a9c260a80323
    ---> 9471a2d3b04e
    Removing intermediate container a9c260a80323
    Step 3/5 : RUN apt-get update
    ---> Running in 7d311d26b101
    Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
    Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
    Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
    Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
    Get:5 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]
    ^C
    [root@docker df_test]#
    View Code

      除了上述方法之外,我们也可以在Dockerfile文件中加入环境变量,例如:"ENV REFRESH_DATE 20170719"来标识缓存的刷新时间,达到不使用构建缓存来构建镜像的目的。

      查看镜像构建过程:

      如果想要查看一个镜像的构建过程,可以通过“docker history [image]“命令查看该镜像的构建过程。

    [root@docker ~]# docker history centos/nginx
    IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
    858a832d9ded        3 hours ago         /bin/sh -c #(nop)  CMD ["/usr/sbin/nginx" ...   0B                  
    79e047a5307d        3 hours ago         /bin/sh -c #(nop)  EXPOSE 80/tcp                0B                  
    cc4253355736        3 hours ago         /bin/sh -c #(nop) COPY file:628683707d4b12...   131B                
    2e79bdc2c38d        3 hours ago         /bin/sh -c yum install -y nginx                 102MB               
    07b7841d020a        3 hours ago         /bin/sh -c wget -O /etc/yum.repos.d/CentOS...   3.66kB              
    18e4181821e3        3 hours ago         /bin/sh -c mkdir -p tmp/ && mv /etc/yum.re...   8.79kB              
    f6a03ba7b4af        3 hours ago         /bin/sh -c cd /etc/yum.repos.d/                 0B                  
    91203c1a1e18        3 hours ago         /bin/sh -c yum install -y wget                  107MB               
    b24dd05d3f3d        3 hours ago         /bin/sh -c #(nop)  MAINTAINER fngje "fngje...   0B                  
    36540f359ca3        13 days ago         /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B                  
    <missing>           13 days ago         /bin/sh -c #(nop)  LABEL name=CentOS Base ...   0B                  
    <missing>           13 days ago         /bin/sh -c #(nop) ADD file:23c65acc4aae2af...   193MB               
    [root@docker ~]#
    View Code
  • 相关阅读:
    filter 静态资源
    getRequestURI,getRequestURL的区别
    基于NodeJs的网页爬虫的构建(二)
    基于NodeJs的网页爬虫的构建(一)
    Reverse Words in a String
    Sum Root to Leaf Numbers
    Search Insert Position
    Wildcard Matching
    Trapping Rain Water
    Gray Code
  • 原文地址:https://www.cnblogs.com/jie-fang/p/7207452.html
Copyright © 2020-2023  润新知