Docker build: Difference between revisions
Line 13: | Line 13: | ||
docker build [''options''] <''path''>|<''url''>|- | docker build [''options''] <''path''>|<''url''>|- | ||
The default location for the Dockerfile is the current directory, and the path is "." | The default location for the Dockerfile is the current directory, and the path is "." The image such produced is placed in the [[Docker_Concepts#Local_Image_Registry|local registry]], using the repository name and the [[Docker_Concepts#Tag|image tag]] provided with [[#-t|-t command line option]]. | ||
==The Build Context== | ==The Build Context== |
Revision as of 01:27, 5 December 2017
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.
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
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
If the only Dockerfile instruction is FROM, the build command simply downloads the base image into the local registry.
--rm
--rm=true
Remove intermediate containers after a successful build (default true).
Todeplete
Takes a Dockerfile and produces a Docker image. The default location for the Dockerfile is the current directory: the local directory must contain the Dockerfile and whatever else is required to go into the image.
docker build -t <tag> <path>|<url>|-
docker build -t novaordistest/run-loop .
docker build .
The image goes into the local registry and it is declared as belonging to the <path>|<url> repository. If no URL is provided, the repository will be inferred from the base image's repository.
docker images REPOSITORY TAG IMAGE ID CREATED SIZE novaordistest/run-loop latest c22308970610 5 minutes ago 1.13 MB
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