Docker build: Difference between revisions
No edit summary |
|||
Line 13: | Line 13: | ||
docker build [''options''] <''path''>|<''url''>|- | docker build [''options''] <''path''>|<''url''>|- | ||
=The Build Context= | ==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 ''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. | ||
Line 19: | Line 19: | ||
The URL may refer to Git repositories, pre-package TAR files and plain text files. | The URL may refer to Git repositories, pre-package TAR files and plain text files. | ||
=.dockerignore= | ==.dockerignore== | ||
{{Internal|.dockerignore|.dockerignore}} | {{Internal|.dockerignore|.dockerignore}} | ||
=Options= | |||
==--rm== | |||
--rm=true | |||
Remove intermediate containers after a successful build (default true). | |||
==-t, --tag== | |||
Name and optionally a tag in the 'name:tag' format (default []). | |||
=Todeplete= | =Todeplete= | ||
Line 89: | Line 102: | ||
Successfully built c22308970610 | Successfully built c22308970610 | ||
</pre> | </pre> | ||
Revision as of 01:01, 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 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
--rm
--rm=true
Remove intermediate containers after a successful build (default true).
-t, --tag
Name and optionally a tag in the 'name:tag' format (default []).
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