【问题标题】:Why is docker build not showing any output from commands?为什么 docker build 不显示命令的任何输出?
【发布时间】:2021-02-24 12:10:28
【问题描述】:

来自我的Dockerfile的片段:

FROM node:12.18.0
RUN echo "hello world"
RUN psql --version

当我运行docker build . 时,我看不到这两个命令的任何输出,即使它们没有被缓存。文档说 docker build 默认情况下是详细的。为什么我看不到命令​​的输出?我以前见过他们。

构建时的输出:

=> [7/18] RUN echo "hello worl"                         0.9s

构建完成后我看到的输出:

=> CACHED [6/18] RUN apt-get install postgresql -y      0.0s
=> [7/18] RUN echo "HELLO world"                        6.4s
=> [8/18] RUN psql --version                           17.1s

Dockerfile 是从基于 Debian 9 的 node:12.18.0 创建的。

Docker 版本 19.03.13,内部版本 4484c46d9d。

【问题讨论】:

  • 请发布格式化代码而不是屏幕截图。屏幕截图会中断搜索、复制和粘贴,并且不易访问。

标签: docker docker-build


【解决方案1】:

您显示的输出来自 buildkit,它是 docker 附带的经典构建引擎的替代品。您可以使用 --progress 选项调整输出:

  --progress string         Set type of progress output (auto, plain, tty). Use plain to show container output
                            (default "auto")

添加--progress=plain 将显示未从缓存加载的运行命令的输出。


如果您不想使用 buildkit,您可以通过在 shell 中导出 DOCKER_BUILDKIT=0 来恢复到旧的构建引擎,例如:

DOCKER_BUILDKIT=0 docker build ...

export DOCKER_BUILDKIT=0
docker build ...

【讨论】:

  • 关于--progress=plain 的答案似乎不再起作用。对我来说,在 OS X 上,它只是吐出命令、哈希和步骤结果(例如“CACHED”)。现在仅强制禁用 buildkit 会返回任何有用的输出。这是最近的变化,还是因平台而异?
  • @Jon 如果步骤被缓存,则不运行任何命令,因此没有输出可显示。有无 buildkit 都一样。
  • 使用docker build --progress=plain --no-cache ... 禁用缓存并打印所有输出
  • 我不建议禁用构建工具包。
  • @ruohola 我也不会。这就是我推动--progress=plain 的原因。但有些人不管你给出什么建议,都只是想用旧的方式做事。
【解决方案2】:

只需在build 之后使用此标志--progress=plain

例如:

docker-compose build --progress=plain <container_name>

docker build --progress=plain .

如果你不想每次都使用这个标志,那么永久告诉 docker 使用这个标志:

export BUILDKIT_PROGRESS=plain

这里是你输入docker build --help时的官方文档。

--progress string         Set type of progress output (auto, plain, tty). Use plain to show container output (default "auto")

【讨论】:

  • 您可能需要清除 docker build 缓存才能看到输出,而不是之前构建的哈希值。一种蛮力的方法是docker system prune
【解决方案3】:

作为指定 --progress=plain 选项的替代方法,您还可以通过在 shell 配置中设置此环境变量来永久禁用“漂亮”输出:

export BUILDKIT_PROGRESS=plain

【讨论】:

  • 这是金子,谢谢。对于 devops 管道非常有用!
【解决方案4】:

在 Docker 20.10 中,我也必须使用 --no-cache 标志。否则不会显示缓存的输出。

docker build --progress=plain --no-cache .

【讨论】:

  • --no-cache 不仅隐藏了缓存的输出,它还完全禁用了 Docker 的层缓存。您当然不想一直使用它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-25
  • 1970-01-01
  • 1970-01-01
  • 2021-06-30
  • 2019-02-13
  • 1970-01-01
相关资源
最近更新 更多