0
点赞
收藏
分享

微信扫一扫

如何提取指定镜像的 Dockerfile

seuleyang 2023-01-20 阅读 14

文章目录

Docker history

docker

docker history nginx:1.16
IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
dfcfd8e9a5d3   2 years ago   /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B
<missing>      2 years ago   /bin/sh -c #(nop)  STOPSIGNAL SIGTERM           0B
<missing>      2 years ago   /bin/sh -c #(nop)  EXPOSE 80                    0B
<missing>      2 years ago   /bin/sh -c ln -sf /dev/stdout /var/log/nginx…   22B
<missing>      2 years ago   /bin/sh -c set -x     && addgroup --system -…   57.5MB
<missing>      2 years ago   /bin/sh -c #(nop)  ENV PKG_RELEASE=1~buster     0B
<missing>      2 years ago   /bin/sh -c #(nop)  ENV NJS_VERSION=0.3.8        0B
<missing>      2 years ago   /bin/sh -c #(nop)  ENV NGINX_VERSION=1.16.1     0B
<missing>      2 years ago   /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B
<missing>      2 years ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B
<missing>      2 years ago   /bin/sh -c #(nop) ADD file:9b8be2b52ee0fa31d…   69.2MB
docker history nginx:1.16 --format '{{json .}}'
{"Comment":"","CreatedAt":"2020-04-23T21:04:39+08:00","CreatedBy":"/bin/sh -c #(nop)  CMD [\"nginx\" \"-g\" \"daemon…","CreatedSince":"2 years ago","ID":"dfcfd8e9a5d3","Size":"0B"}
{"Comment":"","CreatedAt":"2020-04-23T21:04:38+08:00","CreatedBy":"/bin/sh -c #(nop)  STOPSIGNAL SIGTERM","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"0B"}
{"Comment":"","CreatedAt":"2020-04-23T21:04:38+08:00","CreatedBy":"/bin/sh -c #(nop)  EXPOSE 80","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"0B"}
{"Comment":"","CreatedAt":"2020-04-23T21:04:38+08:00","CreatedBy":"/bin/sh -c ln -sf /dev/stdout /var/log/nginx…","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"22B"}
{"Comment":"","CreatedAt":"2020-04-23T21:04:37+08:00","CreatedBy":"/bin/sh -c set -x     \u0026\u0026 addgroup --system -…","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"57.5MB"}
{"Comment":"","CreatedAt":"2020-04-23T21:04:08+08:00","CreatedBy":"/bin/sh -c #(nop)  ENV PKG_RELEASE=1~buster","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"0B"}
{"Comment":"","CreatedAt":"2020-04-23T21:04:08+08:00","CreatedBy":"/bin/sh -c #(nop)  ENV NJS_VERSION=0.3.8","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"0B"}
{"Comment":"","CreatedAt":"2020-04-23T21:04:08+08:00","CreatedBy":"/bin/sh -c #(nop)  ENV NGINX_VERSION=1.16.1","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"0B"}
{"Comment":"","CreatedAt":"2020-04-23T21:02:24+08:00","CreatedBy":"/bin/sh -c #(nop)  LABEL maintainer=NGINX Do…","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"0B"}
{"Comment":"","CreatedAt":"2020-04-23T08:20:32+08:00","CreatedBy":"/bin/sh -c #(nop)  CMD [\"bash\"]","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"0B"}
{"Comment":"","CreatedAt":"2020-04-23T08:20:32+08:00","CreatedBy":"/bin/sh -c #(nop) ADD file:9b8be2b52ee0fa31d…","CreatedSince":"2 years ago","ID":"\u003cmissing\u003e","Size":"69.2MB"}

containerd

nerdctl history alpine/dfimage:1.1
SNAPSHOT                                                                   CREATED        CREATED BY                                       SIZE        COMMENT
<missing>                                                                  2 years ago    /bin/sh -c #(nop)  ENTRYPOINT ["./Whaler"]       0.0 B
sha256:83adc3c3d0f7a262d81eea224265d62381454ea94a2af480e77a57ceb2f3abf2    2 years ago    /bin/sh -c #(nop) COPY file:9cdb17dd7bf71ba8…    14.0 MiB
<missing>                                                                  2 years ago    /bin/sh -c #(nop) WORKDIR /root/                 0.0 B
<missing>                                                                  2 years ago    /bin/sh -c #(nop)  CMD ["/bin/sh"]               0.0 B
sha256:50644c29ef5a27c9a40c393a73ece2479de78325cae7d762ef3cdc19bf42dd0a    2 years ago    /bin/sh -c #(nop) ADD file:c92c248239f8c7b9b…    5.9 MiB
nerdctl history alpine/dfimage:1.1 --format '{{json .}}'
{"Snapshot":"<missing>","CreatedSince":"2 years ago","CreatedBy":"/bin/sh -c #(nop)  ENTRYPOINT [\"./Whaler\"]","Size":"0.0 B","Comment":""}
{"Snapshot":"sha256:83adc3c3d0f7a262d81eea224265d62381454ea94a2af480e77a57ceb2f3abf2","CreatedSince":"2 years ago","CreatedBy":"/bin/sh -c #(nop) COPY file:9cdb17dd7bf71ba8…","Size":"14.0 MiB","Comment":""}
{"Snapshot":"<missing>","CreatedSince":"2 years ago","CreatedBy":"/bin/sh -c #(nop) WORKDIR /root/","Size":"0.0 B","Comment":""}
{"Snapshot":"<missing>","CreatedSince":"2 years ago","CreatedBy":"/bin/sh -c #(nop)  CMD [\"/bin/sh\"]","Size":"0.0 B","Comment":""}
{"Snapshot":"sha256:50644c29ef5a27c9a40c393a73ece2479de78325cae7d762ef3cdc19bf42dd0a","CreatedSince":"2 years ago","CreatedBy":"/bin/sh -c #(nop) ADD file:c92c248239f8c7b9b…","Size":"5.9 MiB","Comment":""}

总结

dfimage

  • 如果想要自己构建 whaler 镜像,whalergithub 项目里面也提供了 Dockerfile,只需要下载好 whaler 的源码包,稍稍修改一下就可以构建了
  • 已经构建好的镜像,也可以直接拿来用
    • pegleg/whaler
    • alpine/dfimage
  • 想自己构建一波的,可以看下面的内容,想快速使用的,可以直接跳到下面的 使用 dfimage 或 whaler

构建 whaler 镜像

wget https://github.com/P3GLEG/Whaler/archive/refs/heads/master.zip
unzip master.zip
vim Dockerfile
FROM golang:1.14.4 AS builder
# 官方这里的 ADD 本地路径直接写了 ./ 所以会有问题,
## 只需要改成解压出来的目录名称就可以了,后面的都可以不做修改
ADD ./Whaler-master /root/whaler_build
WORKDIR /root/whaler_build
RUN export CGO_ENABLED=0 && go build .
RUN cp whaler /root/whaler

FROM alpine:3.12.0
WORKDIR /root/
COPY --from=builder /root/whaler .
ENTRYPOINT ["./whaler"]
nerdctl build -t whaler:latest .

使用 dfimage 或 whaler

docker 的方式

alias dfimage="docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock:ro alpine/dfimage"
alias whaler="docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock:ro pegleg/whaler"
dfimage nginx:1.16
whaler nginx:1.16
Analyzing nginx:1.16
Docker Version: 18.09.7
GraphDriver: overlay2
Environment Variables
|PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|NGINX_VERSION=1.16.1
|NJS_VERSION=0.3.8
|PKG_RELEASE=1~buster

Open Ports
|80

Image user
|User is root

Potential secrets:
Dockerfile:
CMD ["bash"]
LABEL maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>
ENV NGINX_VERSION=1.16.1
ENV NJS_VERSION=0.3.8
ENV PKG_RELEASE=1~buster
RUN set -x  \
        && addgroup --system --gid 101 nginx  \
        && adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx  \
        && apt-get update  \
        && apt-get install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates  \
        && NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; found=''; for server in ha.pool.sks-keyservers.net hkp://keyserver.ubuntu.com:80 hkp://p80.pool.sks-keyservers.net:80 pgp.mit.edu ; do echo "Fetching GPG key $NGINX_GPGKEY from $server"; apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY"  \
        && found=yes  \
        && break; done; test -z "$found"  \
        && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY"  \
        && exit 1; apt-get remove --purge --auto-remove -y gnupg1  \
        && rm -rf /var/lib/apt/lists/*  \
        && dpkgArch="$(dpkg --print-architecture)"  \
        && nginxPackages=" nginx=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-xslt=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-geoip=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-image-filter=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-njs=${NGINX_VERSION}.${NJS_VERSION}-${PKG_RELEASE} "  \
        && case "$dpkgArch" in amd64|i386) echo "deb https://nginx.org/packages/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list  \
        && apt-get update ;; *) echo "deb-src https://nginx.org/packages/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list  \
        && tempDir="$(mktemp -d)"  \
        && chmod 777 "$tempDir"  \
        && savedAptMark="$(apt-mark showmanual)"  \
        && apt-get update  \
        && apt-get build-dep -y $nginxPackages  \
        && ( cd "$tempDir"  \
        && DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" apt-get source --compile $nginxPackages )  \
        && apt-mark showmanual | xargs apt-mark auto > /dev/null  \
        && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; }  \
        && ls -lAFh "$tempDir"  \
        && ( cd "$tempDir"  \
        && dpkg-scanpackages . > Packages )  \
        && grep '^Package: ' "$tempDir/Packages"  \
        && echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list  \
        && apt-get -o Acquire::GzipIndexes=false update ;; esac  \
        && apt-get install --no-install-recommends --no-install-suggests -y $nginxPackages gettext-base  \
        && apt-get remove --purge --auto-remove -y ca-certificates  \
        && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list  \
        && if [ -n "$tempDir" ]; then apt-get purge -y --auto-remove  \
        && rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; fi
RUN ln -sf /dev/stdout /var/log/nginx/access.log  \
        && ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["nginx" "-g" "daemon off;"]
CMD ["bash"]
LABEL maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>
ENV NGINX_VERSION=1.16.1
ENV NJS_VERSION=0.3.8
ENV PKG_RELEASE=1~buster
RUN set -x  \
        && addgroup --system --gid 101 nginx  \
        && adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx  \
        && apt-get update  \
        && apt-get install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates  \
        && NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; found=''; for server in ha.pool.sks-keyservers.net hkp://keyserver.ubuntu.com:80 hkp://p80.pool.sks-keyservers.net:80 pgp.mit.edu ; do echo "Fetching GPG key $NGINX_GPGKEY from $server"; apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY"  \
        && found=yes  \
        && break; done; test -z "$found"  \
        && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY"  \
        && exit 1; apt-get remove --purge --auto-remove -y gnupg1  \
        && rm -rf /var/lib/apt/lists/*  \
        && dpkgArch="$(dpkg --print-architecture)"  \
        && nginxPackages=" nginx=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-xslt=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-geoip=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-image-filter=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-njs=${NGINX_VERSION}.${NJS_VERSION}-${PKG_RELEASE} "  \
        && case "$dpkgArch" in amd64|i386) echo "deb https://nginx.org/packages/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list  \
        && apt-get update ;; *) echo "deb-src https://nginx.org/packages/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list  \
        && tempDir="$(mktemp -d)"  \
        && chmod 777 "$tempDir"  \
        && savedAptMark="$(apt-mark showmanual)"  \
        && apt-get update  \
        && apt-get build-dep -y $nginxPackages  \
        && ( cd "$tempDir"  \
        && DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" apt-get source --compile $nginxPackages )  \
        && apt-mark showmanual | xargs apt-mark auto > /dev/null  \
        && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; }  \
        && ls -lAFh "$tempDir"  \
        && ( cd "$tempDir"  \
        && dpkg-scanpackages . > Packages )  \
        && grep '^Package: ' "$tempDir/Packages"  \
        && echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list  \
        && apt-get -o Acquire::GzipIndexes=false update ;; esac  \
        && apt-get install --no-install-recommends --no-install-suggests -y $nginxPackages gettext-base  \
        && apt-get remove --purge --auto-remove -y ca-certificates  \
        && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list  \
        && if [ -n "$tempDir" ]; then apt-get purge -y --auto-remove  \
        && rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; fi
RUN ln -sf /dev/stdout /var/log/nginx/access.log  \
        && ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["nginx" "-g" "daemon off;"]

containerd 的方式

举报

相关推荐

0 条评论