Docker 构建:如何获得完整的 运行 命令输出?
Docker build: how to get full RUN command output?
更新:本题用MVRE重构
有什么方法可以让我从使用 docker build
构建的 Dockerfile 中看到完整的 RUN
命令?
例如。如果我的 Dockerfile 包含以下语句:
# Dockerfile
FROM alpine:3.7 as base
RUN echo "this is the song that doesn't end. Yes it goes on and on, my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because..."
...有没有办法让我看到完整的命令,即 echo "this is the song that doesn't end. Yes it goes on and on, my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because..."
以及 运行 该命令的完整输出?
我使用 docker 构建工具包(我宁愿不禁用它)构建,默认情况下,它会折叠输出,并截断相对于终端宽度的已执行命令,最终可能看起来像这个:
$ docker build --no-cache -t tmp:tmp .
[+] Building 16.2s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 281B 0.0s
=> [internal] load .dockerignore 0.2s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:3.7 0.0s
=> CACHED [1/2] FROM docker.io/library/alpine:3.7 0.0s
=> [2/2] RUN echo "this is the song that doesn't end. Yes it goes on and on, my fr 2.0s
=> exporting to image 13.9s
=> => exporting layers 0.4s
=> => writing image sha256:d72d9f0e36f38227e2a28dce31781dc9b6089b01cf5645c70f33b2 13.5s
=> => naming to docker.io/library/tmp:tmp 0.0s
...即命令和它的输出都是truncated/collapsed。
说 docker inspect
应该用于此目的,在我的例子中:docker inspect tmp:tmp
,我的答案将在 $[0].Config.Cmd
部分输出,但该部分不包含相关信息:
$ docker inspect tmp:tmp
[
{
...
"Config": {
...
"Cmd": [
"/bin/sh"
],
...
...该 docker inspect
命令的任何其他部分也不包含相关信息(在我的示例中为 cmake
语句)。
建议使用 --progress plain
选项 docker build
。这解开了 命令的输出 ,但它仍然截断了 命令本身 ,例如:
$ docker build --progress plain --no-cache -t tmp:tmp .
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 44B done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.1s
#3 [internal] load metadata for docker.io/library/alpine:3.7
#3 DONE 0.0s
#4 [1/2] FROM docker.io/library/alpine:3.7
#4 CACHED
#5 [2/2] RUN echo "this is the song that doesn't end. Yes it goes on and on...
#5 1.542 this is the song that doesn't end. Yes it goes on and on, my friends. Some people
started singing it not knowing what it was, and they'll continue singing it forever just
because...
#5 DONE 2.1s
#6 exporting to image
#6 exporting layers
#6 exporting layers 0.7s done
#6 writing image sha256:0ce39b23377d91e47e7aa9b4e10e50d5a62a4ef9ec281f1b3e244e4b66a17d02
#6 writing image sha256:0ce39b23377d91e47e7aa9b4e10e50d5a62a4ef9ec281f1b3e244e4b66a17d02 1
3.3s done
#6 naming to docker.io/library/tmp:tmp done
#6 DONE 14.0s
有没有办法让我看到 Dockerfile RUN
语句执行的完整(未截断的)命令(以及命令的未折叠输出)?
我执行的输出 docker history
:
$ docker history tmp:tmp
IMAGE CREATED CREATED BY SIZE COMMENT
0ce39b23377d 3 minutes ago RUN /bin/sh -c echo "this is the song that d… 0B buildkit.dockerfile.v0
<missing> 2 years ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 2 years ago /bin/sh -c #(nop) ADD file:aa17928040e31624c… 4.21MB
设置 env-var PROGRESS_NO_TRUNC=1
和 --progress plain
成功了:
$ PROGRESS_NO_TRUNC=1 docker build --progress plain --no-cache -t tmp:tmp .
#1 [internal] load .dockerignore
#1 sha256:0c3d9a77560c6997674ff903c1fd8166c2b0a0c56b8267c8919f9435df2b6360
#1 transferring context: 0.0s
#1 transferring context: 2B 0.0s done
#1 DONE 0.2s
#2 [internal] load build definition from Dockerfile
#2 sha256:637986daa013bdd36af757aa03cf8b23447a85ed9e3e103fda6234a9d97332cd
#2 transferring dockerfile: 44B 0.1s done
#2 DONE 0.2s
#3 [internal] load metadata for docker.io/library/alpine:3.7
#3 sha256:d05d2c4bcea3dce001a657515352ca6040d02fcc707293d5f7167602950d71ce
#3 DONE 0.0s
#4 [1/2] FROM docker.io/library/alpine:3.7
#4 sha256:c139e859151268321f8b3d9af4bf0195aab52a1b66880ee4294469151c73bfb9
#4 CACHED
#5 [2/2] RUN echo "this is the song that doesn't end. Yes it goes on and on, my friends. S
ome people started singing it not knowing what it was, and they'll continue singing it for
ever just because..."
#5 sha256:63a60e7b5a4ce0944e5135780a681e85c9fc52a776b498fcf0652f563bc0c470
#5 1.381 this is the song that doesn't end. Yes it goes on and on, my friends. Some people
started singing it not knowing what it was, and they'll continue singing it forever just
because...
#5 DONE 1.7s
#6 exporting to image
#6 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#6 exporting layers
#6 exporting layers 0.2s done
#6 writing image sha256:523ddeb4ae29e8f8bbd9e346a07d980024e58d867222ed3d30d552587df72685 0
.0s done
#6 naming to docker.io/library/tmp:tmp 0.0s done
#6 DONE 0.2s
RUN
语句本身以及执行该语句的输出都完整呈现。
更新:本题用MVRE重构
有什么方法可以让我从使用 docker build
构建的 Dockerfile 中看到完整的 RUN
命令?
例如。如果我的 Dockerfile 包含以下语句:
# Dockerfile
FROM alpine:3.7 as base
RUN echo "this is the song that doesn't end. Yes it goes on and on, my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because..."
...有没有办法让我看到完整的命令,即 echo "this is the song that doesn't end. Yes it goes on and on, my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because..."
以及 运行 该命令的完整输出?
我使用 docker 构建工具包(我宁愿不禁用它)构建,默认情况下,它会折叠输出,并截断相对于终端宽度的已执行命令,最终可能看起来像这个:
$ docker build --no-cache -t tmp:tmp .
[+] Building 16.2s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 281B 0.0s
=> [internal] load .dockerignore 0.2s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:3.7 0.0s
=> CACHED [1/2] FROM docker.io/library/alpine:3.7 0.0s
=> [2/2] RUN echo "this is the song that doesn't end. Yes it goes on and on, my fr 2.0s
=> exporting to image 13.9s
=> => exporting layers 0.4s
=> => writing image sha256:d72d9f0e36f38227e2a28dce31781dc9b6089b01cf5645c70f33b2 13.5s
=> => naming to docker.io/library/tmp:tmp 0.0s
...即命令和它的输出都是truncated/collapsed。
docker inspect
应该用于此目的,在我的例子中:docker inspect tmp:tmp
,我的答案将在 $[0].Config.Cmd
部分输出,但该部分不包含相关信息:
$ docker inspect tmp:tmp
[
{
...
"Config": {
...
"Cmd": [
"/bin/sh"
],
...
...该 docker inspect
命令的任何其他部分也不包含相关信息(在我的示例中为 cmake
语句)。
--progress plain
选项 docker build
。这解开了 命令的输出 ,但它仍然截断了 命令本身 ,例如:
$ docker build --progress plain --no-cache -t tmp:tmp .
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 44B done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.1s
#3 [internal] load metadata for docker.io/library/alpine:3.7
#3 DONE 0.0s
#4 [1/2] FROM docker.io/library/alpine:3.7
#4 CACHED
#5 [2/2] RUN echo "this is the song that doesn't end. Yes it goes on and on...
#5 1.542 this is the song that doesn't end. Yes it goes on and on, my friends. Some people
started singing it not knowing what it was, and they'll continue singing it forever just
because...
#5 DONE 2.1s
#6 exporting to image
#6 exporting layers
#6 exporting layers 0.7s done
#6 writing image sha256:0ce39b23377d91e47e7aa9b4e10e50d5a62a4ef9ec281f1b3e244e4b66a17d02
#6 writing image sha256:0ce39b23377d91e47e7aa9b4e10e50d5a62a4ef9ec281f1b3e244e4b66a17d02 1
3.3s done
#6 naming to docker.io/library/tmp:tmp done
#6 DONE 14.0s
有没有办法让我看到 Dockerfile RUN
语句执行的完整(未截断的)命令(以及命令的未折叠输出)?
我执行的输出 docker history
:
$ docker history tmp:tmp
IMAGE CREATED CREATED BY SIZE COMMENT
0ce39b23377d 3 minutes ago RUN /bin/sh -c echo "this is the song that d… 0B buildkit.dockerfile.v0
<missing> 2 years ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 2 years ago /bin/sh -c #(nop) ADD file:aa17928040e31624c… 4.21MB
设置 env-var PROGRESS_NO_TRUNC=1
和 --progress plain
成功了:
$ PROGRESS_NO_TRUNC=1 docker build --progress plain --no-cache -t tmp:tmp .
#1 [internal] load .dockerignore
#1 sha256:0c3d9a77560c6997674ff903c1fd8166c2b0a0c56b8267c8919f9435df2b6360
#1 transferring context: 0.0s
#1 transferring context: 2B 0.0s done
#1 DONE 0.2s
#2 [internal] load build definition from Dockerfile
#2 sha256:637986daa013bdd36af757aa03cf8b23447a85ed9e3e103fda6234a9d97332cd
#2 transferring dockerfile: 44B 0.1s done
#2 DONE 0.2s
#3 [internal] load metadata for docker.io/library/alpine:3.7
#3 sha256:d05d2c4bcea3dce001a657515352ca6040d02fcc707293d5f7167602950d71ce
#3 DONE 0.0s
#4 [1/2] FROM docker.io/library/alpine:3.7
#4 sha256:c139e859151268321f8b3d9af4bf0195aab52a1b66880ee4294469151c73bfb9
#4 CACHED
#5 [2/2] RUN echo "this is the song that doesn't end. Yes it goes on and on, my friends. S
ome people started singing it not knowing what it was, and they'll continue singing it for
ever just because..."
#5 sha256:63a60e7b5a4ce0944e5135780a681e85c9fc52a776b498fcf0652f563bc0c470
#5 1.381 this is the song that doesn't end. Yes it goes on and on, my friends. Some people
started singing it not knowing what it was, and they'll continue singing it forever just
because...
#5 DONE 1.7s
#6 exporting to image
#6 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#6 exporting layers
#6 exporting layers 0.2s done
#6 writing image sha256:523ddeb4ae29e8f8bbd9e346a07d980024e58d867222ed3d30d552587df72685 0
.0s done
#6 naming to docker.io/library/tmp:tmp 0.0s done
#6 DONE 0.2s
RUN
语句本身以及执行该语句的输出都完整呈现。