2014-04-16 12:07:55 -06:00
|
|
|
% DOCKER(1) Docker User Manuals
|
|
|
|
% William Henry
|
|
|
|
% APRIL 2014
|
|
|
|
# NAME
|
|
|
|
docker-build - Build a container image from a Dockerfile source at PATH
|
|
|
|
|
|
|
|
# SYNOPSIS
|
2014-04-22 22:35:59 -06:00
|
|
|
**docker build** [**--no-cache**[=*false*]] [**-q**|**--quiet**[=*false*]]
|
|
|
|
[**--rm**] [**-t**|**--tag**=TAG] PATH | URL | -
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
# DESCRIPTION
|
2014-04-17 09:36:58 -06:00
|
|
|
This will read the Dockerfile from the directory specified in **PATH**.
|
|
|
|
It also sends any other files and directories found in the current
|
|
|
|
directory to the Docker daemon. The contents of this directory would
|
|
|
|
be used by **ADD** commands found within the Dockerfile.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
2014-04-17 09:36:58 -06:00
|
|
|
Warning, this will send a lot of data to the Docker daemon depending
|
2014-04-21 14:28:25 -06:00
|
|
|
on the contents of the current directory. The build is run by the Docker
|
2014-04-21 11:55:06 -06:00
|
|
|
daemon, not by the CLI, so the whole context must be transferred to the daemon.
|
|
|
|
The Docker CLI reports "Uploading context" when the context is sent to
|
|
|
|
the daemon.
|
2014-04-17 09:36:58 -06:00
|
|
|
|
|
|
|
When a single Dockerfile is given as the URL, then no context is set.
|
|
|
|
When a Git repository is set as the **URL**, the repository is used
|
|
|
|
as context.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
# OPTIONS
|
|
|
|
|
|
|
|
**-q**, **--quiet**=*true*|*false*
|
2014-04-17 09:36:58 -06:00
|
|
|
When set to true, suppress verbose build output. Default is *false*.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
**--rm**=*true*|*false*
|
2014-04-17 09:36:58 -06:00
|
|
|
When true, remove intermediate containers that are created during the
|
|
|
|
build process. The default is true.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
**-t**, **--tag**=*tag*
|
2014-04-17 09:36:58 -06:00
|
|
|
Tag to be applied to the resulting image on successful completion of
|
|
|
|
the build.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
**--no-cache**=*true*|*false*
|
2014-04-17 09:36:58 -06:00
|
|
|
When set to true, do not use a cache when building the image. The
|
|
|
|
default is *false*.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
# EXAMPLES
|
|
|
|
|
2014-04-17 09:36:58 -06:00
|
|
|
## Building an image using a Dockefile located inside the current directory
|
2014-04-16 12:07:55 -06:00
|
|
|
|
2014-04-17 09:36:58 -06:00
|
|
|
Docker images can be built using the build command and a Dockerfile:
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
docker build .
|
|
|
|
|
2014-04-17 09:36:58 -06:00
|
|
|
During the build process Docker creates intermediate images. In order to
|
2014-04-21 11:55:06 -06:00
|
|
|
keep them, you must explicitly set `--rm=false`.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
docker build --rm=false .
|
|
|
|
|
2014-04-17 09:36:58 -06:00
|
|
|
A good practice is to make a sub-directory with a related name and create
|
|
|
|
the Dockerfile in that directory. For example, a directory called mongo may
|
|
|
|
contain a Dockerfile to create a Docker MongoDB image. Likewise, another
|
|
|
|
directory called httpd may be used to store Dockerfiles for Apache web
|
|
|
|
server images.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
2014-04-17 09:36:58 -06:00
|
|
|
It is also a good practice to add the files required for the image to the
|
|
|
|
sub-directory. These files will then be specified with the `ADD` instruction
|
|
|
|
in the Dockerfile. Note: If you include a tar file (a good practice!), then
|
|
|
|
Docker will automatically extract the contents of the tar file
|
|
|
|
specified within the `ADD` instruction into the specified target.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
## Building an image using a URL
|
|
|
|
|
2014-04-17 09:36:58 -06:00
|
|
|
This will clone the specified Github repository from the URL and use it
|
|
|
|
as context. The Dockerfile at the root of the repository is used as
|
|
|
|
Dockerfile. This only works if the Github repository is a dedicated
|
|
|
|
repository.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
docker build github.com/scollier/Fedora-Dockerfiles/tree/master/apache
|
|
|
|
|
2014-04-17 09:36:58 -06:00
|
|
|
Note: You can set an arbitrary Git repository via the `git://` schema.
|
2014-04-16 12:07:55 -06:00
|
|
|
|
|
|
|
# HISTORY
|
2014-04-17 09:36:58 -06:00
|
|
|
March 2014, Originally compiled by William Henry (whenry at redhat dot com)
|
|
|
|
based on docker.io source material and internal work.
|