← 返回命令列表

Linux command

docker-build 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Build an image from Dockerfile

docker build -t [image_name] .

Build with specific Dockerfile

docker build -f [Dockerfile.dev] -t [image_name] .

Build with build arguments

docker build --build-arg [VAR=value] -t [image_name] .

Build without cache

docker build --no-cache -t [image_name] .

Build for specific platform

docker build --platform [linux/amd64] -t [image_name] .

Build multi-platform image

docker buildx build --platform [linux/amd64,linux/arm64] -t [image_name] .

Build and push to registry

docker build -t [registry/image:tag] --push .

说明

docker build creates Docker images from a Dockerfile and context (files available during build). The Dockerfile contains instructions for assembling the image layer by layer. The build context is sent to the Docker daemon, which processes Dockerfile instructions sequentially. Each instruction creates a layer; layers are cached and reused when unchanged, speeding up subsequent builds. Modern builds use BuildKit (enabled by default in recent Docker versions), providing improved performance, better caching, and features like secrets and SSH forwarding.

参数

-t, --tag _name:tag_
Name and optionally tag the image.
-f, --file _path_
Path to Dockerfile (default: PATH/Dockerfile).
--build-arg _key=value_
Build-time variables.
--no-cache
Don't use cache when building.
--pull
Always pull newer base image.
--target _stage_
Build specific stage in multi-stage Dockerfile.
--platform _platform_
Target platform (linux/amd64, linux/arm64).
--progress _type_
Progress output: auto, plain, tty.
--secret _id=secret_
Secret to expose to build.
--ssh _socket_
SSH agent socket to expose.
-q, --quiet
Suppress build output.
--push
Push image after build (buildx).

FAQ

What is the docker-build command used for?

docker build creates Docker images from a Dockerfile and context (files available during build). The Dockerfile contains instructions for assembling the image layer by layer. The build context is sent to the Docker daemon, which processes Dockerfile instructions sequentially. Each instruction creates a layer; layers are cached and reused when unchanged, speeding up subsequent builds. Modern builds use BuildKit (enabled by default in recent Docker versions), providing improved performance, better caching, and features like secrets and SSH forwarding.

How do I run a basic docker-build example?

Run `docker build -t [image_name] .` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -t, --tag _name:tag_ do in docker-build?

Name and optionally tag the image.