Easy Tutorial
❮ Docker Version Command Docker Install Nginx ❯

Docker build Command

Docker Command Manual


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

Syntax

docker build [OPTIONS] PATH | URL | -

OPTIONS Description:

-

--build-arg=[] : Set variables during image creation;

-

--cpu-shares : Set CPU usage weight;

-

--cpu-period : Limit CPU CFS period;

-

--cpu-quota : Limit CPU CFS quota;

-

--cpuset-cpus : Specify the CPU id to use;

-

--cpuset-mems : Specify the memory id to use;

-

--disable-content-trust : Skip image verification, enabled by default;

-

-f : Specify the path to the Dockerfile;

-

--force-rm : Remove intermediate containers during image creation;

-

--isolation : Use container isolation technology;

-

--label=[] : Set metadata for the image;

-

-m : Set the maximum memory limit;

-

--memory-swap : Set the maximum value for memory + swap, "-1" indicates unlimited swap;

-

--no-cache : Do not use cache when building the image;

-

--pull : Attempt to update the image to the latest version;

-

--quiet, -q : Quiet mode, only output the image ID upon success;

-

--rm : Remove intermediate containers after a successful build;

-

--shm-size : Set the size of /dev/shm, default is 64MB;

-

--ulimit : Ulimit configuration.

-

--squash : Squash all Dockerfile operations into a single layer.

-

--tag, -t: Name and optionally a tag in the 'name:tag' format or 'name'; you can set multiple tags for an image in a single build.

-

--network: Default is 'default'. Set the network mode for the RUN instructions during the build.

Examples

Create an image using the Dockerfile in the current directory with the tag tutorialpro/ubuntu:v1.

docker build -t tutorialpro/ubuntu:v1 .

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

docker build github.com/creack/docker-firefox

You can also specify the location of the Dockerfile with -f:

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

Before the Docker daemon runs the instructions in the Dockerfile, it performs a syntax check on the Dockerfile, and returns an error if the syntax is incorrect:

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

Docker Command Manual

❮ Docker Version Command Docker Install Nginx ❯