Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whati is the purpose of docker build output?

What is the purpose and how to use:

docker build --output

Description from Docker reference

--output , -o API 1.40+ Output destination (format: type=local,dest=path)

Reason for question:

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?

like image 738
henioStraszny Avatar asked Jan 20 '20 13:01

henioStraszny


People also ask

What does make docker build do?

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.

Where is the output of docker build stored?

They get stored as a series of layers in your Docker root directory. On Linux, it's /var/lib/docker .

What does it mean to build a docker image?

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.

What is difference between docker and docker build?

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.


1 Answers

--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#
like image 64
Shashank V Avatar answered Sep 22 '22 12:09

Shashank V