faq,

Tool - Docker build not showing any output from commands(Dockerfile RUN)

中文阅读

Problem Description

Here is the content of Dockerfile:

1
2
3
4
5
6
FROM alpine

ADD . /app/
WORKDIR /app
RUN echo "hello world"
RUN ls -l

When using the new version of Docker to execute docker build, I found that the RUN command has no output.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
❯ docker build -t test -f Dockerfile .
[+] Building 1.0s (10/10) FINISHED                                                                                                                                               
 => [internal] load build definition from Dockerfile                                                                                                                        0.0s
 => => transferring dockerfile: 112B                                                                                                                                        0.0s
 => [internal] load .dockerignore                                                                                                                                           0.0s
 => => transferring context: 2B                                                                                                                                             0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                            0.0s
 => [internal] load build context                                                                                                                                           0.0s
 => => transferring context: 107B                                                                                                                                           0.0s
 => CACHED [1/5] FROM docker.io/library/alpine                                                                                                                              0.0s
 => [2/5] ADD . /app/                                                                                                                                                       0.0s
 => [3/5] WORKDIR /app                                                                                                                                                      0.0s
 => [4/5] RUN echo "hello world"                                                                                                                                            0.4s
 => [5/5] RUN ls -l                                                                                                                                                         0.4s
 => exporting to image                                                                                                                                                      0.1s
 => => exporting layers                                                                                                                                                     0.0s
 => => writing image sha256:95911a7870dbd929ced4a031c65a180310a5480de759b19a5b08556cd443775b                                                                                0.0s
 => => naming to docker.io/library/test 

This is very unfavorable for debugging when building images.

Solution

Add DOCKER_BUILDKIT=0 in front of the docker build command to print the command output like the previous Docker version.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
DOCKER_BUILDKIT=0 docker build -t test -f Dockerfile .
Sending build context to Docker daemon  2.048kB
Step 1/5 : FROM alpine
 ---> 389fef711851
Step 2/5 : ADD . /app/
 ---> 34cccaf2b826
Step 3/5 : WORKDIR /app
 ---> Running in 65eefb594656
Removing intermediate container 65eefb594656
 ---> 07582a62e423
Step 4/5 : RUN echo "hello world"
 ---> Running in bcd94b080379
hello world
Removing intermediate container bcd94b080379
 ---> 6fbc11007cff
Step 5/5 : RUN ls -l
 ---> Running in 8d9423839270
total 4
-rw-r--r--    1 root     root            70 Apr 29 03:07 Dockerfile
Removing intermediate container 8d9423839270
 ---> 7b6aee767fab
Successfully built 7b6aee767fab
Successfully tagged test:latest

Reference

CatchZeng
Written by CatchZeng Follow
I am a boy who likes 💻 deep learning, 📱 mobile and 💻 server development. I like to build some 🔨 tools to improve development efficiency.