5

The answers here don't seem to work. The answer here also doesn't work. I suspect something has changed about Docker's build engine since then.

My 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"]

Which gives this output from build:

✗ 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

Adding --progress plain gives slightly different output but not what I'm looking for, e.g.:

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

How can I get a directory listing during build in 20.10.3? I can exec into the running container but that's a lot more work.

jcollum
  • 43,623
  • 55
  • 191
  • 321

1 Answers1

4

If your build is cached, there's no output from the run to show. You need to include --no-cache to run the command again for any output to display, and also include --progress plain to output to the console.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • See also https://stackoverflow.com/questions/64804749/why-is-docker-build-not-showing-any-output-from-commands#comment122075618_64805337 – BMitch Mar 28 '22 at 16:43
  • Ran `docker build --no-cache -f build/api/Dockerfile` -- the output has ` => [7/7] RUN ls -alh` but no ls output. Tried adding `RUN echo "hello?"` to the Dockerfile but there's no "hello?" in the output. There is only one Dockerfile in the directory tree. Here's the output: https://imgur.com/CkWy3vT – jcollum Mar 28 '22 at 17:05
  • 1
    Where's the `--progress plain` option? – BMitch Mar 28 '22 at 17:29
  • Damn, I must have missed that. Thanks. Deleting the question since it actually is a duplicate. – jcollum Mar 28 '22 at 20:16
  • 2
    @jcollum I just marked it as a duplicate for you. Sometimes they can be useful for those that find this googling later. – BMitch Mar 28 '22 at 20:19
  • thanks, that makes sense – jcollum Apr 20 '22 at 16:28