docker compose build: Build Service Images
Build the images for services that define a build section.
docker compose build builds (or rebuilds) images for services with a build: config. This page covers no-cache, build args, and using BuildKit cache in CI.
What it does
docker compose build builds images for services that specify build: (context/Dockerfile). Services with only image: are pulled, not built. It does not start anything - pair with docker compose up.
Common usage
docker compose build
docker compose build --no-cache
docker compose build --build-arg NODE_ENV=production api
docker compose build --pullCommon errors in CI
"services.api.build: context: no such file or directory" means the build context path in the compose file does not exist relative to the file - paths are relative to the compose file, not the cwd. A service with only image: cannot be built ("does not have a build section"). For CI cache, set the service build.cache_from or use docker compose build with a BuildKit builder.