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?
The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.
They get stored as a series of layers in your Docker root directory. On Linux, it's /var/lib/docker .
A Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container, like a template. Docker images also act as the starting point when using Docker. An image is comparable to a snapshot in virtual machine (VM) environments.
docker build builds a new image from the source code. docker create creates a writeable container from the image and prepares it for running. docker run creates the container (same as docker create ) and runs it.
--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#
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With