Docker Compose — build, pull, push

1 minute read

Manage images — building local Dockerfiles, pulling from registries, and pushing built images.

docker compose build

docker compose build              # Build all services with build:
docker compose build api          # Build specific service
docker compose build --no-cache   # Ignore layer cache
docker compose build --pull       # Pull latest base images
docker compose build --progress=plain  # Verbose build output

Build Flags

Flag Purpose
--no-cache Rebuild from scratch
--pull Always pull fresh base images
--progress=plain Line-by-line output (debug)
--parallel Build in parallel (default)

docker compose pull

docker compose pull              # Pull all images
docker compose pull db cache     # Pull specific services
docker compose pull --ignore-pull-failures  # Continue on errors

Useful before up to ensure you have the latest images:

docker compose pull && docker compose up -d

docker compose push

docker compose push              # Push all built images
docker compose push api          # Push specific service

Requires image: alongside build: in your compose file:

services:
  api:
    build: ./api
    image: ghcr.io/myorg/api:latest   # Tag for push

docker compose images

List images used by services:

docker compose images
CONTAINER         REPOSITORY          TAG       IMAGE ID       SIZE
myapp-api-1       ghcr.io/myorg/api   latest    abc123def456   150MB
myapp-db-1        postgres            16        789ghi012jkl   380MB
myapp-cache-1     redis               7         mno345pqr678   130MB

Build + Deploy Workflow

# 1. Build images
docker compose build

# 2. Tag with version
VERSION=$(git describe --tags)

# 3. Push to registry
docker compose push

# 4. Deploy on server
docker compose pull
docker compose up -d

Summary

Command Purpose
build Build images from Dockerfiles
build --no-cache Fresh build, no cache
pull Download images from registry
push Upload built images to registry
images List images used

Quick Reference

Item Detail
build Build all services with Dockerfiles
build –no-cache Skip layer cache
pull Download latest images
push Upload built images
images List images used by services