【问题标题】:Whati is the purpose of docker build output?docker build 输出的目的是什么?
【发布时间】:2020-05-06 12:34:56
【问题描述】:

用途和使用方法:

docker build --output

Description from Docker reference

--output , -o API 1.40+ 输出目的地(格式:type=local,dest=path)

提问原因:

我使用 docker 作为构建引擎,我希望找到在docker build 期间或之后导出文件或变量的一些原因。有帮助吗?

【问题讨论】:

    标签: docker build continuous-integration dockerfile


    【解决方案1】:

    --output 标志用于设置buildkit 图像生成器的输出配置。 buildkit 可从 docker 18.09 版本获得。您目前需要使用环境变量DOCKER_BUILDKIT=1 来使用buildkit。

    buildkit 本身支持构建输出到不同的目的地,例如docker image or local directory or as docker tar ball or oci format tar ball。但是使用docker cli 工具,看起来您只能将构建输出导出到本地目录。

    语法

    --output type=local,dest=path/to/output-dir
    

    示例

    root@vm1:~/cc# DOCKER_BUILDKIT=1 docker build -o type=local,dest=/root/cc/out .
    [+] Building 0.5s (5/5) FINISHED
     => [internal] load .dockerignore                                                                                                     0.0s
     => => transferring context: 2B                                                                                                       0.0s
     => [internal] load build definition from Dockerfile                                                                                  0.0s
     => => transferring dockerfile: 49B                                                                                                   0.0s
     => [internal] load metadata for docker.io/library/ubuntu:latest                                                                      0.0s
     => [1/1] FROM docker.io/library/ubuntu                                                                                               0.0s
     => => resolve docker.io/library/ubuntu:latest                                                                                        0.0s
     => exporting to client                                                                                                               0.5s
     => => copying files 64.40MB
    
    # cd /root/cc/out
    # ls -lrt
    total 76
    drwxr-xr-x  2 root root 4096 Apr 24  2018 sys
    drwxr-xr-x  2 root root 4096 Apr 24  2018 proc
    drwxr-xr-x  2 root root 4096 Apr 24  2018 home
    drwxr-xr-x  2 root root 4096 Apr 24  2018 boot
    drwxr-xr-x  2 root root 4096 Jan 12 13:09 srv
    drwxr-xr-x  2 root root 4096 Jan 12 13:09 opt
    drwxr-xr-x  2 root root 4096 Jan 12 13:09 mnt
    drwxr-xr-x  2 root root 4096 Jan 12 13:09 media
    drwxrwxrwt  2 root root 4096 Jan 12 13:10 tmp
    drwxr-xr-x  2 root root 4096 Jan 12 13:10 dev
    drwxr-xr-x  2 root root 4096 Jan 20 07:33 bin
    drwxr-xr-x 29 root root 4096 Jan 20 07:33 etc
    drwxr-xr-x  8 root root 4096 Jan 20 07:33 lib
    drwxr-xr-x  5 root root 4096 Jan 20 07:33 run
    drwx------  2 root root 4096 Jan 20 07:33 root
    drwxr-xr-x  2 root root 4096 Jan 20 07:33 lib64
    drwxr-xr-x  2 root root 4096 Jan 20 07:33 sbin
    drwxr-xr-x 10 root root 4096 Jan 20 07:33 usr
    drwxr-xr-x 11 root root 4096 Jan 20 07:33 var
    root@vm1:~/cc/out#
    

    【讨论】:

    • 感谢您的解释,那么是否可以同时构建镜像以上传到 docker 注册表并将其导出到本地路径以访问构建工件?
    • @JacekStyrylski 我需要做同样的事情。你解决了吗?
    • 您是否检查过docker save 是否对您的目的有用?
    • @henioStraszny 您可以将两个输出作为两个单独的构建命令进行。 Docker 将缓存构建,因此第二个命令几乎是即时的。
    猜你喜欢
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 2015-03-21
    • 2018-10-18
    • 2022-07-04
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    相关资源
    最近更新 更多