当前位置: 首页 > 知识库问答 >
问题:

如何在Docker 20.10.3中构建期间输出目录列表?(2022年3月)[副本]

郑茂材
2023-03-14

这里的答案似乎不起作用。这里的答案也不适用。我怀疑从那以后Docker的构建引擎发生了一些变化。

我的Dockerfile:

FROM node:16.14.2-alpine

WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn
COPY dist .
EXPOSE $SEEDSERV_PORT
RUN pwd
RUN echo "output"
RUN ls -alh
RUN contents="$(ls -1 /usr/src/app)" && echo $contents

# CMD ["node","server.js"]
ENTRYPOINT ["tail", "-f", "/dev/null"]

这将生成以下输出:

✗ docker build --progress auto  --build-arg SEEDSERV_PORT=9999 -f build/api/Dockerfile .
[+] Building 2.1s (14/14) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                    0.1s
 => => transferring dockerfile: 37B                                                                                                                                                                                     0.0s
 => [internal] load .dockerignore                                                                                                                                                                                       0.0s
 => => transferring context: 2B                                                                                                                                                                                         0.0s
 => [internal] load metadata for docker.io/library/node:16.14.2-alpine                                                                                                                                                  1.9s
 => [internal] load build context                                                                                                                                                                                       0.0s
 => => transferring context: 122B                                                                                                                                                                                       0.0s
 => [1/9] FROM docker.io/library/node:16.14.2-alpine@sha256:da7ef512955c906b6fa84a02295a56d0172b2eb57e09286ec7abc02cfbb4c726                                                                                            0.0s
 => CACHED [2/9] WORKDIR /usr/src/app                                                                                                                                                                                   0.0s
 => CACHED [3/9] COPY package.json yarn.lock ./                                                                                                                                                                         0.0s
 => CACHED [4/9] RUN yarn                                                                                                                                                                                               0.0s
 => CACHED [5/9] COPY dist .                                                                                                                                                                                            0.0s
 => CACHED [6/9] RUN pwd                                                                                                                                                                                                0.0s
 => CACHED [7/9] RUN echo "output"                                                                                                                                                                                      0.0s
 => CACHED [8/9] RUN ls -alh                                                                                                                                                                                            0.0s
 => CACHED [9/9] RUN contents="$(ls -1 /usr/src/app)" && echo $contents                                                                                                                                                 0.0s
 => exporting to image                                                                                                                                                                                                  0.0s
 => => exporting layers                                                                                                                                                                                                 0.0s
 => => writing image sha256:d1dd7ac452ecacc803eed2bb1deff654c3296a5576b6f418dbd07c5f2e644f1a                                                                                                                            0.0s

添加--progress plain会产生稍微不同的输出,但不是我想要的,例如:

#11 [7/9] RUN echo "output"
#11 sha256:634e07d201926b0f70289515fcf4a7303cac3658aeddebfa9552fc3054ed4ace
#11 CACHED

在20.10.3版本的构建过程中,我如何获得目录列表?我可以执行到正在运行的容器中,但这需要做更多的工作。

共有1个答案

卜昂熙
2023-03-14

如果您的生成被缓存,则运行中没有要显示的输出。要再次运行命令以显示任何输出,您需要包括--no cache,还需要包括--progress plain以输出到控制台。

 类似资料: