Docker build: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 51: Line 51:
Remove intermediate containers after a successful build (default true).
Remove intermediate containers after a successful build (default true).


=Building Interesting Containers=
=Container Recipes=


* [[Building a Container that Loops]]
* [[Building a Container that Loops]]

Revision as of 03:01, 18 January 2018

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 it will be "dangling". For more details see -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

.dockerignore

Options

-t, --tag

Even if the option is named "tag", it actually specifies the target image repository URL, ignoring the registry host name - the image is always placed in the local registry. In one of its simplest variants, the URL can be just a tag, indeed. Most commonly, the URL contains the namespace and the repository name, or just the repository name. For more details about a repository URL, see: URL.

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. An "unnamed" images is called "dangling":


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 will be "unnamed" (dangled) and the new image that has just been built replaces it.

--rm

--rm=true

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

Container Recipes