使用带有 HEREDOC 的 RUN 时如何改进 Docker 构建输出?

问题描述 投票:0回答:1

给定 Dockerfile:

FROM <some-image>
RUN <<`
  set -e
  # do multiple lines of commands
`

这是

docker buildx build
期间的输出:

=> [2/2] 奔跑 <<` (set -e...)

不清楚这是哪个

RUN
命令,因为任何使用此 HEREDOC 格式的命令看起来都是一样的。我希望能够使用这种 HEREDOC 格式,同时让构建输出更加清晰,例如:

RUN <<` echo Installing deps...
  set -e
  # do multiple lines of commands
`

给出输出:

=> [2/2] 跑步 <<` echo Installing deps...

所以我可以清楚地看到正在执行哪个

RUN
HEREDOC。但这不起作用,也不起作用:

RUN <<` # Installing deps...
  set -e
  # do multiple lines of commands
`

因为多行 HEREDOC 在执行时会串在一起,形成单行。


为了解决这个问题,我可以在使用 HEREDOC 的

ECHO
指令之前简单地添加
RUN

RUN echo Installing deps...
RUN <<`
  set -e
  # do multiple lines of commands
`

But is it the proper way, since it adds a useless `RUN` directive?
docker dockerfile
1个回答
0
投票

使用

set -x
调试 shell 脚本。

© www.soinside.com 2019 - 2024. All rights reserved.