<返回更多

如何从Docker镜像中提取Dockerfile?

2021-06-25    私情不私心
加入收藏

虽然Docker history命令可以看到所有历史层级的操作,但是还是需要手动去写Dockerfile

dfimage就是这样一个工具

dfimage是一个alpine的镜像,启动的时候,通过将docker.sock映射到容器内部来运行,通常将这个操作做成别名

下载镜像

docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage:latest

设置别名

alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage:latest"

测试Nginx查看

1、先pull下nginx镜像

docker pull nginx:latest

2、测试

dfimage -sV=1.36 nginx:latest

输出的结果

Analyzing nginx:latest
Docker Version: 19.03.12
GraphDriver: overlay2
Environment Variables
|PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|NGINX_VERSION=1.21.0
|NJS_VERSION=0.5.3
|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.21.0
ENV NJS_VERSION=0.5.3
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 "FetchingGPG 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|arm64) echo "deb https://nginx.org/packages/mainline/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list  
    && apt-get update ;; *) echo "deb-src https://nginx.org/packages/mainline/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 curl  
    && apt-get remove --purge --auto-remove -y  
    && 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  
    && ln -sf /dev/stdout /var/log/nginx/access.log  
    && ln -sf /dev/stderr /var/log/nginx/error.log  
    && mkdir /docker-entrypoint.d
COPY file:65504f71f5855ca017fb64d502ce873a31b2e0decd75297a8fb0a287f97acf92 in /
    docker-entrypoint.sh

COPY file:0b866ff3fc1ef5b03c4e6c8c513ae014f691fb05d530257dfffd07035c1b75da in /docker-entrypoint.d
    docker-entrypoint.d/
    docker-entrypoint.d/10-listen-on-ipv6-by-default.sh

COPY file:0fd5fca330dcd6a7de297435e32af634f29f7132ed0550d342cad9fd20158258 in /docker-entrypoint.d
    docker-entrypoint.d/
    docker-entrypoint.d/20-envsubst-on-templates.sh

COPY file:09a214a3e07c919af2fb2d7c749ccbc446b8c10eb217366e5a65640ee9edcc25 in /docker-entrypoint.d
    docker-entrypoint.d/
    docker-entrypoint.d/30-tune-worker-processes.sh

ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 80
STOPSIGNAL SIGQUIT
CMD ["nginx" "-g" "daemon off;"]

通过dfimage去生成nginx的Dockerfile,其实就是启动一个容器工具,执行完之后即删除

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>