使用dfimage工具从Docker镜像提取Dockerfile
本文最后更新于 328 天前,其中的信息可能已经有所发展或是发生改变。

有时候因为自己构建镜像的 Dockerfile 文件丢失,或者从网上下载的 Docker 镜像,想了解其镜像构建的步骤,这时候怎么办了?可通过以下两种方法获取。

# 顺便提一下,Rocky Linux 也有 Docker 镜像哦
❯ docker pull rockylinux/rocky-toolbox:9

# 方法一
❯ docker history rockylinux/rocky-toolbox:9
IMAGE          CREATED        CREATED BY                                      SIZE      COMMENT
ab7dfed87582   37 hours ago   /bin/sh -c #(nop) CMD /bin/sh                   309MB     FROM docker.io/library/rockylinux:9
<missing>      37 hours ago   /bin/sh -c dnf clean all                        0B
<missing>      37 hours ago   /bin/sh -c rm /extra-packages                   0B
<missing>      37 hours ago   /bin/sh -c dnf -y install $(<extra-packages)    0B
<missing>      37 hours ago   /bin/sh -c #(nop) COPY file:ed241a206672b4f1…   0B
<missing>      37 hours ago   /bin/sh -c rm /missing-docs                     0B
<missing>      37 hours ago   /bin/sh -c dnf -y reinstall $(<missing-docs)    0B
<missing>      37 hours ago   /bin/sh -c #(nop) COPY file:bf19b43f85a7bbd9…   0B
<missing>      37 hours ago   /bin/sh -c dnf -y update                        0B
<missing>      37 hours ago   /bin/sh -c sed -i '/tsflags=nodocs/d' /etc/d…   0B
<missing>      37 hours ago   /bin/sh -c #(nop) COPY file:b1da0728c04ba266…   0B
<missing>      37 hours ago   /bin/sh -c #(nop) LABEL com.github.container…   0B

# 方法二
❯ alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage"
# 查看相关镜像的构建命令
❯ dfimage -sV=1.36 rockylinux/rocky-toolbox:9                                                                                                                               at 21:21:54   100% 
Analyzing rockylinux/rocky-toolbox:9
Docker Version:
GraphDriver: overlay2
Environment Variables
|PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Image user
|User is root

Potential secrets:
|Found match etc/ssh/ssh_config Client SSH Config .?ssh_config[\s\S]* ab51801f1a3b22f130cf29e6261096ea4e3db66cda8472b4317967ca1d103f57/layer.tar
|Found match etc/ssh/ssh_config.d Client SSH Config .?ssh_config[\s\S]* ab51801f1a3b22f130cf29e6261096ea4e3db66cda8472b4317967ca1d103f57/layer.tar
|Found match etc/ssh/ssh_config.d/50-redhat.conf Client SSH Config .?ssh_config[\s\S]* ab51801f1a3b22f130cf29e6261096ea4e3db66cda8472b4317967ca1d103f57/layer.tar
|Found match root/.ssh SSH file \.ssh$ ab51801f1a3b22f130cf29e6261096ea4e3db66cda8472b4317967ca1d103f57/layer.tar
|Found match var/lib/dnf/history.sqlite Database file \.sqlite$ ab51801f1a3b22f130cf29e6261096ea4e3db66cda8472b4317967ca1d103f57/layer.tar
|Found match var/lib/rpm/rpmdb.sqlite Database file \.sqlite$ ab51801f1a3b22f130cf29e6261096ea4e3db66cda8472b4317967ca1d103f57/layer.tar
Dockerfile:
COPY file:b1da0728c04ba266a0e6590f8f297d999a29954b4ea207b879ba8eef062eab1f in /

RUN sed -i '/tsflags=nodocs/d' /etc/dnf/dnf.conf
RUN dnf -y update
COPY file:bf19b43f85a7bbd9684355acd9cb82fd9c1e2772f3e36b94f0eec8a95e868c18 in /

RUN dnf -y reinstall $(<missing-docs)
RUN rm /missing-docs
COPY file:ed241a206672b4f140fc843c2da283e997479fb6a5f30744289e1c6d713c606f in /

RUN dnf -y install $(<extra-packages)
RUN rm /extra-packages
RUN dnf clean all
CMD /bin/sh
Avatar photo

关于 木子

Founder of the Rocky Linux Chinese community, MVP、VMware vExpert、TVP, advocate for cloud native technologies, with over ten years of experience in site reliability engineering (SRE) and the DevOps field. Passionate about Cloud Computing、Microservices、CI&CD、DevOps、Kubernetes, currently dedicated to promoting and implementing Rocky Linux in Chinese-speaking regions.
用一杯咖啡支持我们,我们的每一篇[文档]都经过实际操作和精心打磨,而不是简单地从网上复制粘贴。期间投入了大量心血,只为能够真正帮助到您。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇