docker image build

Estimated reading time: 4 minutes


Build an image from a Dockerfile


docker image build [OPTIONS] PATH | URL | -


Name, shorthandDefaultDescription
--add-hostAdd a custom host-to-IP mapping (host:ip)
--build-argSet build-time variables
--cache-fromImages to consider as cache sources
--cgroup-parentOptional parent cgroup for the container
--compressCompress the build context using gzip
--cpu-periodLimit the CPU CFS (Completely Fair Scheduler) period
--cpu-quotaLimit the CPU CFS (Completely Fair Scheduler) quota
--cpu-shares , -cCPU shares (relative weight)
--cpuset-cpusCPUs in which to allow execution (0-3, 0,1)
--cpuset-memsMEMs in which to allow execution (0-3, 0,1)
--disable-content-trusttrueSkip image verification
--file , -fName of the Dockerfile (Default is ‘PATH/Dockerfile’)
--force-rmAlways remove intermediate containers
--iidfileWrite the image ID to the file
--isolationContainer isolation technology
--labelSet metadata for an image
--memory , -mMemory limit
--memory-swapSwap limit equal to memory plus swap: ‘-1’ to enable unlimited swap
--networkAPI 1.25+
Set the networking mode for the RUN instructions during build
--no-cacheDo not use cache when building the image
--platformexperimental (daemon)API 1.32+
Set platform if server is multi-platform capable
--pullAlways attempt to pull a newer version of the image
--quiet , -qSuppress the build output and print image ID on success
--rmtrueRemove intermediate containers after a successful build
--security-optSecurity options
--shm-sizeSize of /dev/shm
--squashexperimental (daemon)API 1.25+
Squash newly built layers into a single new layer
--streamexperimental (daemon)API 1.31+
Stream attaches to server to negotiate build context
--tag , -tName and optionally a tag in the ‘name:tag’ format
--targetSet the target build stage to build.
--ulimitUlimit options

Parent command

docker imageManage images
docker image buildBuild an image from a Dockerfile
docker image historyShow the history of an image
docker image importImport the contents from a tarball to create a filesystem image
docker image inspectDisplay detailed information on one or more images
docker image loadLoad an image from a tar archive or STDIN
docker image lsList images
docker image pruneRemove unused images
docker image pullPull an image or a repository from a registry
docker image pushPush an image or a repository to a registry
docker image rmRemove one or more images
docker image saveSave one or more images to a tar archive (streamed to STDOUT by default)
docker image tagCreate a tag TARGET_IMAGE that refers to SOURCE_IMAGE