Docker build Command

Docker build Command

docker build command is used to create an image using Dockerfile.

Docker build Syntax

docker build [OPTIONS] PATH | URL | -

OPTIONS description.

  • –build-arg=[] : Set the variables to be used when the image is created.
  • –cpu-shares : Set cpu usage weights.
  • –cpu-period : limit CPU CFS cycles.
  • –cpu-quota : limit CPU CFS quotas; –cpu-quota : limit CPU CFS quotas.
  • –cpuset-cpus : specify the CPU id to be used.
  • –cpuset-mems : specify the memory id to be used.
  • –disable-content-trust : ignore checksum, enabled by default.
  • -f : specify the path to the Dockerfile to use.
  • –force-rm : set the deletion of intermediate containers during the mirroring process.
  • –isolation : use container isolation techniques.
  • –label=[] : set the metadata used by the mirror.
  • –m : setting the memory maximum.
  • –memory-swap : set the maximum value of Swap to memory+swap, "-1" means unlimited swap.
  • –no-cache : the process of creating a mirror does not use cache.
  • –pull : try to update the mirror with a new version.
  • –quiet, -q : Quiet mode, output only the mirror ID upon success.
  • –rm : set to delete intermediate containers after successful mirroring.
  • –shm-size : set the size of /dev/shm, the default value is 64M.
  • –ulimit :Ulimit configuration.
  • –squash : Compress all operations in Dockerfile into one layer.
  • –tag, -t: The name and tag of the image, usually name:tag or name format; you can set multiple tags for a single image in a single build.
  • —network: default default. set the network mode of the RUN command during the build

Docker build Example

Create an image using the Dockerfile of the current directory, labeled apidemos/ubuntu:v1.

docker build -t apidemos/ubuntu:v1 . 

Create an image using the Dockerfile at URL github.com/creack/docker-firefox.

docker build github.com/creack/docker-firefox

The location of the Dockerfile file can also be accessed by -f:

$ docker build -f /path/to/a/Dockerfile .

Before the Docker daemon executes the commands in the Dockerfile, it first checks the syntax of the Dockerfile and returns the following if there is a syntax error.

$ docker build -t test/myapp .
Sending build context to Docker daemon 2.048 kB
Error response from daemon: Unknown instruction: RUNCMD
Like(0)