Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

docker compose build Command

docker compose build Command

Docker Command ReferenceDocker Command Reference


The docker compose build command builds service images based on the definitions in the docker-compose.yml file.

docker compose build builds images from the specified Dockerfile or build context and prepares containers for all services.

Syntax

docker compose build [OPTIONS] [SERVICE...]

OPTIONS:

Example

1. Build images for all services



docker compose build

Build images for all services according to the configuration in docker-compose.yml.

** 2. Build images for specific services**



docker compose build web

Build the image only for the web service.

** 3. Build images without cache**



docker compose build --no-cache

Force Docker to build all images from scratch without using previously built cache layers.

** 4. Build from the latest base image**



docker compose build --pull

Make sure Docker pulls the latest base image instead of using the local one.

** 5. Pass build variables**



docker compose build --build-arg NODE_ENV=production

Pass the variables needed at build time through --build-arg, for example the NODE_ENV environment variable.


Docker Command ReferenceDocker Command Reference