Merge pull request #15677 from moxiegirl/carry-14714-changes

remove references to 'source repository'
This commit is contained in:
Sebastiaan van Stijn 2015-08-19 00:56:41 +02:00
commit d997351e97
1 changed files with 39 additions and 37 deletions

View File

@ -10,48 +10,50 @@ parent = "mn_reference"
# Dockerfile reference # Dockerfile reference
**Docker can build images automatically** by reading the instructions Docker can build images automatically by reading the instructions from a
from a `Dockerfile`. A `Dockerfile` is a text document that contains all `Dockerfile`. A `Dockerfile` is a text document that contains all the commands a
the commands you would normally execute manually in order to build a user could call on the command line to assemble an image. Using `docker build`
Docker image. By calling `docker build` from your terminal, you can have users can create an automated build that executes several command-line
Docker build your image step by step, executing the instructions instructions in succession.
successively.
This page discusses the specifics of all the instructions you can use in your This page describes the commands you can use in a `Dockerfile`. When you are
`Dockerfile`. To further help you write a clear, readable, maintainable done reading this page, refer to the [`Dockerfile` Best
`Dockerfile`, we've also written a [`Dockerfile` Best Practices Practices](/articles/dockerfile_best-practices) for a tip-oriented guide.
guide](/articles/dockerfile_best-practices). Lastly, you can test your
Dockerfile knowledge with the [Dockerfile tutorial](/userguide/level1).
## Usage ## Usage
To [*build*](/reference/commandline/build) an image from a source repository, The [`docker build`](/reference/commandline/build/) command builds an image from
create a description file called `Dockerfile` at the root of your repository. a `Dockerfile` and a *context*. The build's context is the files at a specified
This file will describe the steps to assemble the image. location `PATH` or `URL`. The `PATH` is a directory on your local filesystem.
The `URL` is a the location of a Git repository.
Then call `docker build` with the path of your source repository as the argument A context is processed recursively. So, a `PATH` includes any subdirectories and
(for example, `.`): the `URL` includes the repository and its submodules. A simple build command
that uses the current directory as context:
$ docker build . $ docker build .
Sending build context to Docker daemon 6.51 MB
...
The path to the source repository defines where to find the *context* of The build is run by the Docker daemon, not by the CLI. The first thing a build
the build. The build is run by the Docker daemon, not by the CLI, so the process does is send the entire context (recursively) to the daemon. In most
whole context must be transferred to the daemon. The Docker CLI reports cases, it's best to start with an empty directory as context and keep your
"Sending build context to Docker daemon" when the context is sent to the daemon. Dockerfile in that directory. Add only the files needed for building the
Dockerfile.
> **Warning** >**Warning**: Do not use your root directory, `/`, as the `PATH` as it causes
> Avoid using your root directory, `/`, as the root of the source repository. The >the build to transfer the entire contents of your hard drive to the Docker
> `docker build` command will use whatever directory contains the Dockerfile as the build >daemon.
> context (including all of its subdirectories). The build context will be sent to the
> Docker daemon before building the image, which means if you use `/` as the source
> repository, the entire contents of your hard drive will get sent to the daemon (and
> thus to the machine running the daemon). You probably don't want that.
In most cases, it's best to put each Dockerfile in an empty directory. Then, To use a file in the build context, the `Dockerfile` refers to the file with
only add the files needed for building the Dockerfile to the directory. To an instruction, for example, a `COPY` instruction. To increase the build's
increase the build's performance, you can exclude files and directories by performance, exclude files and directories by adding a `.dockerignore` file to
adding a `.dockerignore` file to the directory. For information about how to the context directory. For information about how to [create a `.dockerignore`
[create a `.dockerignore` file](#dockerignore-file) on this page. file](#dockerignore-file) see the documentation on this page.
Traditionally, the `Dockerfile` is called `Dockerfile` and located in the root
of the context. You use the `-f` flag with `docker build` to point to a Dockerfile
anywhere in your file system.
You can specify a repository and tag at which to save the new image if You can specify a repository and tag at which to save the new image if
the build succeeds: the build succeeds: