December 08, 2017

Docker Commands: docker build

Docker Commands: docker build


docker build -t <DockerID>/<ImageName> <Dockerfile name>

To build a new image using a Dockerfile.


Using docker build is the preferred way to build a Docker Image. The build instructions are laid out in the Dockerfile, which allows an automated, documented and repeatable way to generate a specific Docker image.

Associated with the docker build command is its context. The build’s context is the files at a specified location: PATH or URL.

PATH is a directory on your local filesystem
URL is a Git repository location

A context is processed recursively, i.e. any subdirectories in the PATH and any submodules in the URL are processed for objects.

By default the build instructions are read from a file called Dockerfile at the root (or top level) of your context. In the example below,  if the docker build command is run from a subdirectory called Files, this becomes its context. The Docker daemon searches this directory and any subdirectories for objects it needs, e.g. Dockerfile.


Note: if the Dockerfile is located outside the context, use the -f option to specify the Dockerfile, e.g. $ docker build -f /path/to/a/Dockerfile .

Note: You can specify a repository (and tag) at which to save the new image, e.g. $ docker build -t neokobo/alp01data:1.0 .

Reference:

Creative Commons License Licensed under a Creative Commons Attribution 4.0 International License.

No comments:

Post a Comment