没有命令直接 通过image镜像 就能反编译 获得 Dockerfile。

但是 我们可以根据 docker history命令 进行反推。

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 images 找到镜像id和tag

zhangxiaofans-MacBook-Pro:Downloads joe$ docker images
REPOSITORY                                                       TAG                 IMAGE ID            CREATED             SIZE
debian                                                           stretch             6b14557ccda6        2 months ago        101MB

使用history命令

zhangxiaofans-MacBook-Pro:Downloads joe$ docker history  debian:stretch
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
6b14557ccda6        2 months ago        /bin/sh -c #(nop)  CMD ["bash"]                 0B                  
<missing>           2 months ago        /bin/sh -c #(nop) ADD file:08c5ab7c53526da15…   101MB               
zhangxiaofans-MacBook-Pro:Downloads joe$ 

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

自定义输出格式:–format

docker history  debian:stretch --format "table {{.ID}}\t{{.CreatedBy}}" --no-trunc

输出如下:

zhangxiaofans-MacBook-Pro:Downloads joe$ docker history  debian:stretch --format "table {{.ID}}\t{{.CreatedBy}}" --no-trunc
IMAGE                                                                     CREATED BY
sha256:6b14557ccda6d43137ebcf46490778af1c8bae98e26b49e1f5ca216bcb9ebf20   /bin/sh -c #(nop)  CMD ["bash"]
<missing>                                                                 /bin/sh -c #(nop) ADD file:08c5ab7c53526da155d6be40a9795fc08afc9f47bd333c096e90185fe9fab2b1 in / 
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐