Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`docker build` show output from `RUN` [duplicate]

I have this Dockerfile, where I run a command with RUN, and I want to see its output when running docker build:

FROM alpine:3.14
COPY . .
RUN echo "here are some numbers: $(seq 10)"

When I run docker build ., it doesn't show the output of the above command:

[+] Building 2.8s (8/8) FINISHED                                                                                                           
 => [internal] load build definition from Dockerfile                                                                                  0.0s
 => => transferring dockerfile: 36B                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                     0.0s
 => => transferring context: 2B                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/alpine:3.14                                                                        1.2s
 => [internal] load build context                                                                                                     0.1s
 => => transferring context: 188.24kB                                                                                                 0.1s
 => CACHED [1/3] FROM docker.io/library/alpine:3.14@sha256:234cb88d3020898631af0ccbbcca9a66ae7306ecd30c9720690858c1b007d2a0           0.0s
 => [2/3] COPY . .                                                                                                                    0.4s
 => [3/3] RUN echo "here are some numbers: $(seq 10)"                                                                                 0.2s
 => exporting to image                                                                                                                0.8s
 => => exporting layers                                                                                                               0.8s
 => => writing image sha256:7e0bf9ff04a7b4a3a53395d430ddd950500be9a53733cce22a1da1929cae1a0a                                          0.0s 
                                                                                                                                           
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them.

How do I see what the output is?

Docker version:

$ docker --version
Docker version 20.10.6, build 370c289
like image 440
Waleed Khan Avatar asked Dec 11 '25 09:12

Waleed Khan


2 Answers

Is that what are you looking for?

$ docker build --progress=plain .
Sending build context to Docker daemon  4.096kB
Step 1/3 : FROM alpine:3.14
3.14: Pulling from library/alpine
5843afab3874: Pull complete 
Digest: sha256:234cb88d3020898631af0ccbbcca9a66ae7306ecd30c9720690858c1b007d2a0
Status: Downloaded newer image for alpine:3.14
 ---> d4ff818577bc
Step 2/3 : COPY . .
 ---> 106aa79185ae
Step 3/3 : RUN echo "here are some numbers: $(seq 10)"
 ---> Running in 30a81b6d5035
here are some numbers: 1
2
3
4
5
6
7
8
9
10
Removing intermediate container 30a81b6d5035
 ---> 3c059c9b6150
Successfully built 3c059c9b6150
$ docker --version
Docker version 19.03.8, build afacb8b
like image 66
rzlvmp Avatar answered Dec 14 '25 06:12

rzlvmp


Docker is showing the output as it's generated, and then hiding it when the command is done. You can disable this interactive output by piping docker build to a file or pager. Make sure to pipe stderr as well as stdout. For example, in bash, the result of the command appears in item #7 here:

$ docker build . |& cat
#1 [internal] load build definition from Dockerfile
#1 sha256:0ce5eece4291db925ff5f4646c0f72c5c94a28a77431c2afd38ffa4c5a90ccab
#1 transferring dockerfile: 36B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:96c5d624b98a42c7926385cf683312588be6b5b47ce4512bbc5a0a59c4042367
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/alpine:3.14
#3 sha256:af035606328a1ce217c0e290353f888d2ee03ed437bef601e11d9cc421fbbb67
#3 DONE 0.9s

#4 [1/3] FROM docker.io/library/alpine:3.14@sha256:234cb88d3020898631af0ccbbcca9a66ae7306ecd30c9720690858c1b007d2a0
#4 sha256:2c66994e2bde1811eaa777244107d7b0d683d113e151d83a5f7aa09e37e1883f
#4 DONE 0.0s

#5 [internal] load build context
#5 sha256:c87370e17d42a78ca943cd74a0d2d983bc71dc609a92739af5013ed4373e31a6
#5 transferring context: 188.24kB 0.1s done
#5 DONE 0.1s

#4 [1/3] FROM docker.io/library/alpine:3.14@sha256:234cb88d3020898631af0ccbbcca9a66ae7306ecd30c9720690858c1b007d2a0
#4 sha256:2c66994e2bde1811eaa777244107d7b0d683d113e151d83a5f7aa09e37e1883f
#4 CACHED

#6 [2/3] COPY . .
#6 sha256:200618f800c74119b8db3b01ff18105a07477dcfae41f0528189443421f6ba31
#6 DONE 0.4s

#7 [3/3] RUN echo "here are some numbers: $(seq 10)"
#7 sha256:c094a42d846e25e5586053168f7231e17248fc7f09c75de1199642ad83688952
#7 0.241 here are some numbers: 1
#7 0.241 2
#7 0.241 3
#7 0.241 4
#7 0.241 5
#7 0.241 6
#7 0.241 7
#7 0.241 8
#7 0.241 9
#7 0.241 10
#7 DONE 0.3s

#8 exporting to image
#8 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#8 exporting layers
#8 exporting layers 0.8s done
#8 writing image sha256:7b4e8d44804bba048cf5aa47c58cd57ab701400143177fb63887ef51edc1a23b done
#8 DONE 0.8s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
like image 24
Waleed Khan Avatar answered Dec 14 '25 05:12

Waleed Khan