docker build不输出echo内容,不打印构建过程

文章目录

  • 1. 背景
  • 2. 解决方案
    • 2.1. 方案一 (不推荐)
    • 2.2. 方案二 (强烈推荐)
  • 3. 测试
    • 3.1. 不使用任何参数构建过程
    • 3.2. 使用DOCKER_BUILDKIT参数构建过程
    • 3.3. 使用--progress=plain参数构建过程

1. 背景

  升级了docker版本,发现在构建镜像过程中,docker没有输出echo, ls, pwd等类似命令的类容,并且没有输出构建过程。老版本的docker则没有这个问题(具体哪个版本没有深究)

2. 解决方案

2.1. 方案一 (不推荐)

  增加DOCKER_BUILDKIT参数,譬如这么执行构建命令:DOCKER_BUILDKIT=0 docker build .

2.2. 方案二 (强烈推荐)

  增加--progress=plain参数,譬如这么执行构建命令:docker build --no-cache --progress=plain .

3. 测试

  dockerfile测试文件如下:

FROM ubuntu:22.04

RUN echo "aa"
RUN ls -ll

3.1. 不使用任何参数构建过程

[root@8f7059cd1fc5 ~/test-dockerfile]# docker build .
[+] Building 33.7s (7/7) FINISHED                                                                                                                                                                                      docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                                             0.0s
 => => transferring dockerfile: 80B                                                                                                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                0.0s
 => => transferring context: 2B                                                                                                                                                                                                  0.0s
 => [internal] load metadata for docker.io/library/ubuntu:22.04                                                                                                                                                                 30.7s
 => [ 1/33] FROM docker.io/library/ubuntu:22.04@sha256:aabed3296a3d45cede1dc866a24476c4d7e093aa806263c27ddaadbdce3c1054                                                                                                        403.8s
 => => resolve docker.io/library/ubuntu:22.04@sha256:aabed3296a3d45cede1dc866a24476c4d7e093aa806263c27ddaadbdce3c1054                                                                                                           30.9s
 => => sha256:aabed3296a3d45cede1dc866a24476c4d7e093aa806263c27ddaadbdce3c1054 1.13kB / 1.13kB                                                                                                                                   0.0s
 => => sha256:b492494d8e0113c4ad3fe4528a4b5ff89faa5331f7d52c5c138196f69ce176a6 424B / 424B                                                                                                                                       0.0s
 => => sha256:c6b84b685f35f1a5d63661f5d4aa662ad9b7ee4f4b8c394c022f25023c907b65 2.30kB / 2.30kB                                                                                                                                   0.0s
 => => sha256:445a6a12be2be54b4da18d7c77d4a41bc4746bc422f1f4325a60ff4fc7ea2e5d 29.54MB / 29.54MB                                                                                                                               370.0s
 => => extracting sha256:445a6a12be2be54b4da18d7c77d4a41bc4746bc422f1f4325a60ff4fc7ea2e5d                                                                                                                                        2.5s
 => [2/3] RUN echo "aa"                                                                                                                                                                                                          2.4s
 => [3/3] RUN ls -ll                                                                                                                                                                                                             0.4s 
 => exporting to image                                                                                                                                                                                                           0.0s
 => => exporting layers                                                                                                                                                                                                          0.0s
 => => writing image sha256:d44fb2351af002391cb8e1082161b9b62cb1f5d09d2d86d896fa3d39e6813631                                                                                                                                     0.0s
[root@8f7059cd1fc5 ~/test-dockerfile]# 

3.2. 使用DOCKER_BUILDKIT参数构建过程

[root@8f7059cd1fc5 ~/test-dockerfile]# 
[root@8f7059cd1fc5 ~/test-dockerfile]# DOCKER_BUILDKIT=0 docker build --no-cache  .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            BuildKit is currently disabled; enable it by removing the DOCKER_BUILDKIT=0
            environment-variable.

Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM ubuntu:22.04
22.04: Pulling from library/ubuntu
445a6a12be2b: Already exists 
Digest: sha256:aabed3296a3d45cede1dc866a24476c4d7e093aa806263c27ddaadbdce3c1054
Status: Downloaded newer image for ubuntu:22.04
 ---> c6b84b685f35
Step 2/3 : RUN echo "aa"
 ---> Running in 0482ec8dc4d8
aa
Removing intermediate container 0482ec8dc4d8
 ---> dbd1157070f6
Step 3/3 : RUN ls -ll
 ---> Running in cb136517b1e9
total 48
lrwxrwxrwx   1 root root    7 Aug 16 02:02 bin -> usr/bin
drwxr-xr-x   2 root root 4096 Apr 18  2022 boot
drwxr-xr-x   5 root root  340 Sep 28 03:28 dev
drwxr-xr-x   1 root root 4096 Sep 28 03:28 etc
drwxr-xr-x   2 root root 4096 Apr 18  2022 home
lrwxrwxrwx   1 root root    7 Aug 16 02:02 lib -> usr/lib
lrwxrwxrwx   1 root root    9 Aug 16 02:02 lib32 -> usr/lib32
lrwxrwxrwx   1 root root    9 Aug 16 02:02 lib64 -> usr/lib64
lrwxrwxrwx   1 root root   10 Aug 16 02:02 libx32 -> usr/libx32
drwxr-xr-x   2 root root 4096 Aug 16 02:03 media
drwxr-xr-x   2 root root 4096 Aug 16 02:03 mnt
drwxr-xr-x   2 root root 4096 Aug 16 02:03 opt
dr-xr-xr-x 365 root root    0 Sep 28 03:28 proc
drwx------   2 root root 4096 Aug 16 02:06 root
drwxr-xr-x   5 root root 4096 Aug 16 02:06 run
lrwxrwxrwx   1 root root    8 Aug 16 02:02 sbin -> usr/sbin
drwxr-xr-x   2 root root 4096 Aug 16 02:03 srv
dr-xr-xr-x  13 root root    0 Sep 28 03:28 sys
drwxrwxrwt   2 root root 4096 Aug 16 02:06 tmp
drwxr-xr-x  14 root root 4096 Aug 16 02:03 usr
drwxr-xr-x  11 root root 4096 Aug 16 02:06 var
Removing intermediate container cb136517b1e9
 ---> 37eb405c7449
Successfully built 37eb405c7449

3.3. 使用–progress=plain参数构建过程

[root@8f7059cd1fc5 ~/test-dockerfile]# docker build --no-cache --progress=plain .
#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 80B done
#1 DONE 0.1s

#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.1s

#3 [internal] load metadata for docker.io/library/ubuntu:22.04
#3 DONE 31.5s

#4 [ 1/33] FROM docker.io/library/ubuntu:22.04@sha256:aabed3296a3d45cede1dc866a24476c4d7e093aa806263c27ddaadbdce3c1054
#4 resolve docker.io/library/ubuntu:22.04@sha256:aabed3296a3d45cede1dc866a24476c4d7e093aa806263c27ddaadbdce3c1054 30.9s done
#4 sha256:aabed3296a3d45cede1dc866a24476c4d7e093aa806263c27ddaadbdce3c1054 1.13kB / 1.13kB done
#4 sha256:b492494d8e0113c4ad3fe4528a4b5ff89faa5331f7d52c5c138196f69ce176a6 424B / 424B done
#4 sha256:c6b84b685f35f1a5d63661f5d4aa662ad9b7ee4f4b8c394c022f25023c907b65 2.30kB / 2.30kB done
#4 sha256:445a6a12be2be54b4da18d7c77d4a41bc4746bc422f1f4325a60ff4fc7ea2e5d 29.54MB / 29.54MB 370.0s done
#4 extracting sha256:445a6a12be2be54b4da18d7c77d4a41bc4746bc422f1f4325a60ff4fc7ea2e5d 2.5s done
#4 DONE 403.8s

#5 [2/3] RUN echo "aa"
#5 0.491 aa
#5 DONE 0.5s

#6 [3/3] RUN ls -ll
#6 0.450 total 48
#6 0.450 lrwxrwxrwx   1 root root    7 Aug 16 02:02 bin -> usr/bin
#6 0.450 drwxr-xr-x   2 root root 4096 Apr 18  2022 boot
#6 0.450 drwxr-xr-x   5 root root  340 Sep 28 03:26 dev
#6 0.450 drwxr-xr-x  32 root root 4096 Aug 16 02:06 etc
#6 0.450 drwxr-xr-x   2 root root 4096 Apr 18  2022 home
#6 0.450 lrwxrwxrwx   1 root root    7 Aug 16 02:02 lib -> usr/lib
#6 0.450 lrwxrwxrwx   1 root root    9 Aug 16 02:02 lib32 -> usr/lib32
#6 0.450 lrwxrwxrwx   1 root root    9 Aug 16 02:02 lib64 -> usr/lib64
#6 0.450 lrwxrwxrwx   1 root root   10 Aug 16 02:02 libx32 -> usr/libx32
#6 0.450 drwxr-xr-x   2 root root 4096 Aug 16 02:03 media
#6 0.450 drwxr-xr-x   2 root root 4096 Aug 16 02:03 mnt
#6 0.450 drwxr-xr-x   2 root root 4096 Aug 16 02:03 opt
#6 0.450 dr-xr-xr-x 381 root root    0 Sep 28 03:26 proc
#6 0.450 drwx------   2 root root 4096 Aug 16 02:06 root
#6 0.450 drwxr-xr-x   5 root root 4096 Aug 16 02:06 run
#6 0.450 lrwxrwxrwx   1 root root    8 Aug 16 02:02 sbin -> usr/sbin
#6 0.450 drwxr-xr-x   2 root root 4096 Aug 16 02:03 srv
#6 0.450 dr-xr-xr-x  13 root root    0 Sep 28 03:26 sys
#6 0.450 drwxrwxrwt   2 root root 4096 Aug 16 02:06 tmp
#6 0.450 drwxr-xr-x  14 root root 4096 Aug 16 02:03 usr
#6 0.450 drwxr-xr-x  11 root root 4096 Aug 16 02:06 var
#6 DONE 0.5s

#7 exporting to image
#7 exporting layers done
#7 writing image sha256:4ad0b974d54190047ad7719c848a762fee837653458e13d23e7c8134bd9832a3 done
#7 DONE 0.0s
[root@8f7059cd1fc5 ~/test-dockerfile]# 

你可能感兴趣的:(Docker,docker,容器,构建,build,调试dockerfile)