Skip to content
Latchkey

How to Build Images With Compose in a CI Pipeline

docker compose build builds every service that has a build section, using the same file your app runs from so images match production.

Run docker compose build to build all services, or name specific ones. Combine with docker compose push to publish tags once the build succeeds.

Steps

  • Add a build: context (and optional image: tag) to each service.
  • Run docker compose build in CI.
  • Push with docker compose push after a successful build.

Compose file and CI

docker-compose.yml
services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
    image: registry.example.com/api:${GIT_SHA}

CI step

.github/workflows/ci.yml
steps:
  - run: GIT_SHA=${{ github.sha }} docker compose build
  - run: GIT_SHA=${{ github.sha }} docker compose push

Gotchas

  • A service needs an image: name for docker compose push to know where to publish it.
  • Set --pull on build to refresh base images so CI does not use a stale cached base.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →