通过docker history查看镜像构建过程(即dockerfile)

半兽人 发表于: 2019-01-21   最后更新时间: 2019-01-21 14:39:56  
{{totalSubscript}} 订阅, 6,056 游览

介绍:

docker history --help
Usage:  docker history [OPTIONS] IMAGE
Show the history of an image
Options:
      --format string   Pretty-print images using a Go template
      --help            Print usage
  -H, --human           Print sizes and dates in human readable format (default true)
      --no-trunc        Don't truncate output
  -q, --quiet           Only show numeric IDs

示例:


docker history kubeguide/tomcat-app:v1
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
a29e200a18e9        2 years ago         /bin/sh -c #(nop) ADD dir:c5c3bddef49cbc9f...   992kB               
<missing>           2 years ago         /bin/sh -c #(nop) MAINTAINER bestme <bestm...   0B                  
<missing>           2 years ago         /bin/sh -c #(nop) CMD ["catalina.sh" "run"]     0B                  
<missing>           2 years ago         /bin/sh -c #(nop) EXPOSE 8080/tcp               0B                  
<missing>           2 years ago         /bin/sh -c set -e  && nativeLines="$(catal...   0B                  
<missing>           2 years ago         /bin/sh -c set -x   && curl -fSL "$TOMCAT_...   16.6MB              
<missing>           2 years ago         /bin/sh -c #(nop) ENV TOMCAT_TGZ_URL=https...   0B                  
<missing>           2 years ago         /bin/sh -c #(nop) ENV TOMCAT_VERSION=8.0.35     0B                  
<missing>           2 years ago         /bin/sh -c #(nop) ENV TOMCAT_MAJOR=8            0B                  
<missing>           2 years ago         /bin/sh -c set -ex  && for key in   05AB33...   114kB               
<missing>           2 years ago         /bin/sh -c apt-get update && apt-get insta...   7.18MB              
<missing>           2 years ago         /bin/sh -c {   echo 'deb https://httpredir....   172B                
<missing>           2 years ago         /bin/sh -c #(nop) ENV OPENSSL_VERSION=1.0....   0B                  
<missing>           2 years ago         /bin/sh -c #(nop) WORKDIR /usr/local/tomcat     0B                  
<missing>           2 years ago         /bin/sh -c mkdir -p "$CATALINA_HOME"            0B                  
<missing>           2 years ago         /bin/sh -c #(nop) ENV PATH=/usr/local/tomc...   0B                  
<missing>           2 years ago         /bin/sh -c #(nop) ENV CATALINA_HOME=/usr/l...   0B                  
<missing>           2 years ago         /bin/sh -c set -x  && apt-get update  && a...   163MB               
<missing>           2 years ago         /bin/sh -c #(nop) ENV JAVA_DEBIAN_VERSION=...   0B                  
<missing>           2 years ago         /bin/sh -c #(nop) ENV JAVA_VERSION=7u101        0B                  
<missing>           2 years ago         /bin/sh -c #(nop) ENV JAVA_HOME=/usr/lib/j...   0B                  
<missing>           2 years ago         /bin/sh -c {   echo '#!/bin/sh';   echo 's...   87B                 
<missing>           2 years ago         /bin/sh -c #(nop) ENV LANG=C.UTF-8              0B                  
<missing>           2 years ago         /bin/sh -c apt-get update && apt-get insta...   1.17MB              
<missing>           2 years ago         /bin/sh -c apt-get update && apt-get insta...   44.3MB              
<missing>           2 years ago         /bin/sh -c #(nop) CMD ["/bin/bash"]             0B                  
<missing>           2 years ago         /bin/sh -c #(nop) ADD file:5d8521419ad6cfb...   125MB

如果要让CREATED BY 列完整显示,可以加上--no-trunc参数。

自定义输出格式:--format


docker history  kubeguide/tomcat-app:v1 --format "table {{.ID}}\t{{.CreatedBy}}" --no-trunc    
IMAGE                                                                     CREATED BY
sha256:a29e200a18e9b15176cd795710b71d7b1bc97207ed6fcdebba645769c3b01669   /bin/sh -c #(nop) ADD dir:c5c3bddef49cbc9fccc43c460a877566140b173ec039b50478bbaca7b1235585 in /usr/local/tomcat/webapps/demo
<missing>                                                                 /bin/sh -c #(nop) MAINTAINER bestme <bestme@hpe.com>
<missing>                                                                 /bin/sh -c #(nop) CMD ["catalina.sh" "run"]
<missing>                                                                 /bin/sh -c #(nop) EXPOSE 8080/tcp
<missing>                                                                 /bin/sh -c set -e  && nativeLines="$(catalina.sh configtest 2>&1)"  && nativeLines="$(echo "$nativeLines" | grep 'Apache Tomcat Native')"  && nativeLines="$(echo "$nativeLines" | sort -u)"  && if ! echo "$nativeLines" | grep 'INFO: Loaded APR based Apache Tomcat Native library' >&2; then   echo >&2 "$nativeLines";   exit 1;  fi
<missing>                                                                 /bin/sh -c set -x   && curl -fSL "$TOMCAT_TGZ_URL" -o tomcat.tar.gz  && curl -fSL "$TOMCAT_TGZ_URL.asc" -o tomcat.tar.gz.asc  && gpg --batch --verify tomcat.tar.gz.asc tomcat.tar.gz  && tar -xvf tomcat.tar.gz --strip-components=1  && rm bin/*.bat  && rm tomcat.tar.gz*   && nativeBuildDir="$(mktemp -d)"  && tar -xvf bin/tomcat-native.tar.gz -C "$nativeBuildDir" --strip-components=1  && nativeBuildDeps="   gcc   libapr1-dev   libssl-dev   make   openjdk-${JAVA_VERSION%%[-~bu]*}-jdk=$JAVA_DEBIAN_VERSION  "  && apt-get update && apt-get install -y --no-install-recommends $nativeBuildDeps && rm -rf /var/lib/apt/lists/*  && (   export CATALINA_HOME="$PWD"   && cd "$nativeBuildDir/native"   && ./configure    --libdir=/usr/lib/jni    --prefix="$CATALINA_HOME"    --with-apr=/usr/bin/apr-1-config    --with-java-home="$(docker-java-home)"    --with-ssl=yes   && make -j$(nproc)   && make install  )  && apt-get purge -y --auto-remove $nativeBuildDeps  && rm -rf "$nativeBuildDir"  && rm bin/tomcat-native.tar.gz
<missing>                                                                 /bin/sh -c #(nop) ENV TOMCAT_TGZ_URL=https://www.apache.org/dist/tomcat/tomcat-8/v8.0.35/bin/apache-tomcat-8.0.35.tar.gz
<missing>                                                                 /bin/sh -c #(nop) ENV TOMCAT_VERSION=8.0.35
<missing>                                                                 /bin/sh -c #(nop) ENV TOMCAT_MAJOR=8
<missing>                                                                 /bin/sh -c set -ex  && for key in   05AB33110949707C93A279E3D3EFE6B686867BA6   07E48665A34DCAFAE522E5E6266191C37C037D42   47309207D818FFD8DCD3F83F1931D684307A10A5   541FBE7D8F78B25E055DDEE13C370389288584E7   61B832AC2F1C5A90F0F9B00A1C506407564C17A3   79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED   9BA44C2621385CB966EBA586F72C284D731FABEE   A27677289986DB50844682F8ACB77FC2E86E29AC   A9C5DF4D22E99998D9875A5110C01C5A2F6059E7   DCFD35E0BF8CA7344752DE8B6FB21E8933C60243   F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE   F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23  ; do   gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key";  done
<missing>                                                                 /bin/sh -c apt-get update && apt-get install -y --no-install-recommends   libapr1   openssl="$OPENSSL_VERSION"  && rm -rf /var/lib/apt/lists/*
<missing>                                                                 /bin/sh -c {   echo 'deb https://httpredir.debian.org/debian unstable main';  } > /etc/apt/sources.list.d/unstable.list  && {   echo 'Package: *';   echo 'Pin: release a=unstable';   echo 'Pin-Priority: -10';   echo;   echo 'Package: openssl libssl*';   echo "Pin: version $OPENSSL_VERSION";   echo 'Pin-Priority: 990';  } > /etc/apt/preferences.d/unstable-openssl
<missing>                                                                 /bin/sh -c #(nop) ENV OPENSSL_VERSION=1.0.2h-1
<missing>                                                                 /bin/sh -c #(nop) WORKDIR /usr/local/tomcat
<missing>                                                                 /bin/sh -c mkdir -p "$CATALINA_HOME"
<missing>                                                                 /bin/sh -c #(nop) ENV PATH=/usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
<missing>                                                                 /bin/sh -c #(nop) ENV CATALINA_HOME=/usr/local/tomcat
<missing>                                                                 /bin/sh -c set -x  && apt-get update  && apt-get install -y   openjdk-7-jre-headless="$JAVA_DEBIAN_VERSION"  && rm -rf /var/lib/apt/lists/*  && [ "$JAVA_HOME" = "$(docker-java-home)" ]
<missing>                                                                 /bin/sh -c #(nop) ENV JAVA_DEBIAN_VERSION=7u101-2.6.6-1~deb8u1
<missing>                                                                 /bin/sh -c #(nop) ENV JAVA_VERSION=7u101
<missing>                                                                 /bin/sh -c #(nop) ENV JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
<missing>                                                                 /bin/sh -c {   echo '#!/bin/sh';   echo 'set -e';   echo;   echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"';  } > /usr/local/bin/docker-java-home  && chmod +x /usr/local/bin/docker-java-home
<missing>                                                                 /bin/sh -c #(nop) ENV LANG=C.UTF-8
<missing>                                                                 /bin/sh -c apt-get update && apt-get install -y --no-install-recommends   bzip2   unzip   xz-utils  && rm -rf /var/lib/apt/lists/*
<missing>                                                                 /bin/sh -c apt-get update && apt-get install -y --no-install-recommends   ca-certificates   curl   wget  && rm -rf /var/lib/apt/lists/*
<missing>                                                                 /bin/sh -c #(nop) CMD ["/bin/bash"]
<missing>                                                                 /bin/sh -c #(nop) ADD file:5d8521419ad6cfb6956ed26ab70a44422d512f82462046ba8e68b7dcb8283f7e in /


上一条: 到头了!
下一条: 在CentOS/RHEL中安装Docker

查看docker更多相关的文章或提一个关于docker的问题,也可以与我们一起分享文章
提问