Docker build

From NovaOrdis Knowledge Base
Revision as of 21:36, 17 January 2018 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

External

Internal

Overview

docker build expects a Dockerfile and a context and uses the information provided to produce a Docker image.

docker build [options] <path>|<url>|-

The default location for the Dockerfile is the current directory, and the path is "."

The image such produced is placed in the local registry, using the repository name and the image tag provided with -t command line option. Note that if no -t option is use, the image will still be built, but the repository will have no name. For more details see [[]]

The Build Context

The build context is a set of file located in a path, or at an URL, which are specified in the build command line. The commands in the Dockerfile are relative to the context.

The URL may refer to Git repositories, pre-package TAR files and plain text files.

.dockerignore

.dockerignore

Options

-t, --tag

Specifies the repository name and optionally the tag to use to store the image into the local image registry.

docker build -t novaordis/centos-loop:latest .

If no name/tag information is provided, there is no default: the image may be stored with no repository and no tag, just with an image ID:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              4cfda3233bb6        5 seconds ago       204MB

Alternatively, if the only Dockerfile instruction is FROM, or ..., the name and the tag will be inferred from the base image.

If the name/tag combination already exists in the repository, the image they designate is "unnamed" and the new image that has just been built replaces it.

--rm

--rm=true

Remove intermediate containers after a successful build (default true).

Run Example

docker build --rm=true -t novaordistest/run-loop .
Sending build context to Docker daemon 4.608 kB
Step 1 : FROM busybox
 ---> 6ad733544a63
Step 2 : MAINTAINER "Nova Ordis"
 ---> Running in 2ad218dd5e9c
 ---> fbb4cbd9d20e
Removing intermediate container 2ad218dd5e9c
Step 3 : LABEL version "1.0" description "A project that creates a custom Docker image based on a BusyBox base image"
 ---> Running in 2aede00292df
 ---> 9814c9c79887
Removing intermediate container 2aede00292df
Step 4 : ENV NAME "NovaOrdis OpenShift Test Environment" TARGET_DIR "/var/novaordis"
 ---> Running in bb2f8bfa843b
 ---> 40ae6388dd16
Removing intermediate container bb2f8bfa843b
Step 5 : USER root
 ---> Running in 9330a43e9708
 ---> 76ee4eb93f1e
Removing intermediate container 9330a43e9708
Step 6 : COPY run-loop.sh /usr/local/bin/run-loop.sh
 ---> fbf1c0aa45fb
Removing intermediate container 1d2f83c52c79
Step 7 : RUN chmod 755 /usr/local/bin/run-loop.sh
 ---> Running in 9e6a5106ee63
 ---> 2eb53c96e926
Removing intermediate container 9e6a5106ee63
Step 8 : CMD mkdir $TARGET_DIR
 ---> Running in 93cde8761daf
 ---> 60794f39337b
Removing intermediate container 93cde8761daf
Step 9 : VOLUME $TARGET_DIR
 ---> Running in 68b120de3d61
 ---> 3d8a13cc56cf
Removing intermediate container 68b120de3d61
Step 10 : CMD /usr/local/bin/run-loop.sh $NAME
 ---> Running in dfd928793665
 ---> c22308970610
Removing intermediate container dfd928793665
Successfully built c22308970610