Reputation: 303
docker build --output
Description from Docker reference
--output , -o API 1.40+ Output destination (format: type=local,dest=path)
I'm using docker as a build engine and I was hoping to find some why to export a file or variable during or after docker build
. Would it help with that?
Upvotes: 16
Views: 13850
Reputation: 11183
--output
flag is used to set output configuration for buildkit
image builder. buildkit
is available from docker 18.09
release. You need to use the environment variable DOCKER_BUILDKIT=1
to use buildkit currently.
buildkit
itself supports build output to different destinations like a docker image or local directory or as docker tar ball or oci format tar ball. But with docker
cli tool, looks like you can export the build output only to a local directory.
Syntax
--output type=local,dest=path/to/output-dir
Example
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#
Upvotes: 24