ScanSkill

docker build

The command docker build build an image from a Dockerfile and a context. A context is the set of files located in the specified PATH or URL.

Syntax

$ docker build [OPTIONS] PATH | URL | -

Here,

  • Options: --add-host, --build-arg, --cache-from, —memory or -m, --label, —output, --rm, --no-cache, —tag or -t, etc.

Example

  • With a context in the root project directory:
$ docker build .
  • With GitHub URL repositories, from the directory, called cloudyfox in the branch docker
$ docker build <https://github.com/docker/cloudyfox_repo.git#docker:cloudyfox>
  • With remote tarball, (tar archives):
$ docker build <http://cloudyfox-server/context.tar.gz>
  • Build with image tag:
$ docker build -t cloudyfox/serverimage:latest .
  • Specifying a Dockerfile (-f)
$ docker build -f Dockerfile.dev .
$ docker build -f Dockerfile.dev -t cloudyfox/serverimage:latest .
  • Build without context(from STDIN):
$ docker build - < Dockerfile
$ docker build - < context.tar.gz

NOTE: since there is no context, ADD instruction only works if it refers to a remote URL.