docker - 定位给定图像的 Dockerfile

标签 docker

我在 Linux 机器上工作。我大约在 3-4 周前构建了一个 Docker 镜像,但我不记得 Dockerfile 的位置。

找到 Dockerfile 的最佳方法是什么?是否可以根据图像以某种方式获取其位置?

我尝试使用:

$ docker image inspect <image>

但它不显示此信息。

最佳答案

Docker 镜像不会在 Dockerfile 上存储任何信息,但您可以尝试对其进行逆向工程。有几种方法:

  1. 使用docker history <image-name> --no-trunc ,它会显示每一层的信息:
> docker history golang:1.14.2-alpine3.11  --no-trunc --format="{{.CreatedBy}}"
/bin/sh -c #(nop) WORKDIR /go
/bin/sh -c mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
/bin/sh -c #(nop)  ENV PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/bin/sh -c #(nop)  ENV GOPATH=/go
...

  1. https://github.com/CenturyLinkLabs/dockerfile-from-image -- 从 docker 镜像逆向工程 Dockerfile 的项目。你可以这样运行它:
docker run -v /var/run/docker.sock:/var/run/docker.sock \
  centurylink/dockerfile-from-image <IMAGE_TAG_OR_ID>
  1. dive实际上是调试/优化 docker 镜像的工具,但在这种情况下会很有帮助

关于docker - 定位给定图像的 Dockerfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61390606/

相关文章:

docker - 如何在Docker容器中运行 Protractor 端到端测试?

docker - 如何在 docker 容器中的 CLI 前面添加一些内容?

amazon-web-services - 如何使用 Docker 镜像通过 AWS 托管 SSL Rest API?

nginx - 使用 docker 在 nginx 后面运行 Odoo

docker - docker hub 私有(private)注册表中的 "PARALLEL BUILD"是什么?

docker - 如何在 Dockerfile 上运行两个命令?

docker - Docker中的 Guacamole 图像进入空白登录页面

docker - (Kubernetes + Docker) Skaffold 不断终止我的部署文件 : Error: could not stabilize within 2m0s: context deadline exceeded

docker - 如何使用 docker-compose 重启单个容器

docker - 如何在 Ubuntu 14.04 上使用 dotnet CLI 注册新的 NuGet 包源?