2014-04-16 18:07:55 +00:00
% DOCKER(1) Docker User Manuals
2014-07-01 02:58:04 +00:00
% Docker Community
% JUNE 2014
2014-04-16 18:07:55 +00:00
# NAME
2014-07-01 02:58:04 +00:00
docker-build - Build a new image from the source code at PATH
2014-04-16 18:07:55 +00:00
# SYNOPSIS
2014-07-01 02:58:04 +00:00
**docker build**
2014-10-15 21:14:12 +00:00
[**--help**]
2014-09-11 14:42:17 +00:00
[**-f**|**--file**[=*Dockerfile*]]
2014-07-01 02:58:04 +00:00
[**--force-rm**[=*false*]]
[**--no-cache**[=*false*]]
2015-01-07 04:23:32 +00:00
[**--pull**[=*false*]]
2014-07-01 02:58:04 +00:00
[**-q**|**--quiet**[=*false*]]
[**--rm**[=*true*]]
[**-t**|**--tag**[=*TAG*]]
2014-11-28 04:21:55 +00:00
PATH | URL | -
2014-04-16 18:07:55 +00:00
# DESCRIPTION
2014-04-17 15:36:58 +00: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 18:07:55 +00:00
2014-04-17 15:36:58 +00:00
Warning, this will send a lot of data to the Docker daemon depending
2014-04-21 20:28:25 +00:00
on the contents of the current directory. The build is run by the Docker
2014-04-21 17:55:06 +00:00
daemon, not by the CLI, so the whole context must be transferred to the daemon.
2014-05-28 16:59:29 +00:00
The Docker CLI reports "Sending build context to Docker daemon" when the context is sent to
2014-04-21 17:55:06 +00:00
the daemon.
2014-04-17 15:36:58 +00: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 18:07:55 +00:00
# OPTIONS
2014-09-11 14:42:17 +00:00
**-f**, ** --file**=*Dockerfile*
Path to the Dockerfile to use. If the path is a relative path then it must be relative to the current directory. The file must be within the build context. The default is *Dockerfile* .
2014-07-01 02:58:04 +00:00
**--force-rm**=*true*|*false*
Always remove intermediate containers, even after unsuccessful builds. The default is *false* .
**--no-cache**=*true*|*false*
Do not use cache when building the image. The default is *false* .
2014-04-16 18:07:55 +00:00
2014-10-15 21:14:12 +00:00
**--help**
Print usage statement
2015-01-07 04:23:32 +00:00
**--pull**=*true*|*false*
Always attempt to pull a newer version of the image. The default is *false* .
2014-04-16 18:07:55 +00:00
**-q**, ** --quiet**=*true*|*false*
2014-07-01 02:58:04 +00:00
Suppress the verbose output generated by the containers. The default is *false* .
2014-04-16 18:07:55 +00:00
**--rm**=*true*|*false*
2014-07-01 02:58:04 +00:00
Remove intermediate containers after a successful build. The default is *true* .
2014-04-16 18:07:55 +00:00
2014-07-01 02:58:04 +00:00
**-t**, ** --tag**=""
Repository name (and optionally a tag) to be applied to the resulting image in case of success
2014-04-16 18:07:55 +00:00
# EXAMPLES
2015-01-27 03:19:02 +00:00
## Building an image using a Dockerfile located inside the current directory
2014-04-16 18:07:55 +00:00
2014-04-17 15:36:58 +00:00
Docker images can be built using the build command and a Dockerfile:
2014-04-16 18:07:55 +00:00
docker build .
2014-04-17 15:36:58 +00:00
During the build process Docker creates intermediate images. In order to
2014-04-21 17:55:06 +00:00
keep them, you must explicitly set `--rm=false` .
2014-04-16 18:07:55 +00:00
docker build --rm=false .
2014-04-17 15:36:58 +00: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 18:07:55 +00:00
2014-04-17 15:36:58 +00:00
It is also a good practice to add the files required for the image to the
2014-12-12 18:32:11 +00:00
sub-directory. These files will then be specified with the `COPY` or `ADD`
instructions 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 18:07:55 +00:00
2014-05-27 17:56:11 +00:00
## Building an image and naming that image
A good practice is to give a name to the image you are building. There are
2014-05-31 21:44:17 +00:00
no hard rules here but it is best to give the names consideration.
2014-05-27 17:56:11 +00:00
2014-05-27 18:05:48 +00:00
The ** -t**/**--tag** flag is used to rename an image. Here are some examples:
2014-05-27 17:56:11 +00:00
2014-05-31 21:44:17 +00:00
Though it is not a good practice, image names can be arbtrary:
2014-05-27 17:56:11 +00:00
docker build -t myimage .
2014-05-31 21:44:17 +00:00
A better approach is to provide a fully qualified and meaningful repository,
name, and tag (where the tag in this context means the qualifier after
the ":"). In this example we build a JBoss image for the Fedora repository
and give it the version 1.0:
2014-05-27 17:56:11 +00:00
docker build -t fedora/jboss:1.0
2014-05-27 18:05:48 +00:00
The next example is for the "whenry" user repository and uses Fedora and
2014-05-31 21:44:17 +00:00
JBoss and gives it the version 2.1 :
2014-05-27 17:56:11 +00:00
docker build -t whenry/fedora-jboss:V2.1
2014-05-31 21:44:17 +00:00
If you do not provide a version tag then Docker will assign `latest` :
2014-05-27 17:56:11 +00:00
2014-05-31 21:44:17 +00:00
docker build -t whenry/fedora-jboss
When you list the images, the image above will have the tag `latest` .
2014-05-27 17:56:11 +00:00
So renaming an image is arbitrary but consideration should be given to
a useful convention that makes sense for consumers and should also take
into account Docker community conventions.
2014-04-16 18:07:55 +00:00
## Building an image using a URL
2014-04-17 15:36:58 +00: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 18:07:55 +00:00
docker build github.com/scollier/Fedora-Dockerfiles/tree/master/apache
2014-04-17 15:36:58 +00:00
Note: You can set an arbitrary Git repository via the `git://` schema.
2014-04-16 18:07:55 +00:00
# HISTORY
2014-04-17 15:36:58 +00:00
March 2014, Originally compiled by William Henry (whenry at redhat dot com)
2014-07-02 00:30:25 +00:00
based on docker.com source material and internal work.
2014-07-01 02:58:04 +00:00
June 2014, updated by Sven Dowideit < SvenDowideit @ home . org . au >