Compose smarter: use profiles + Buildx Bake to speed local microservices development

When you’re running half a dozen microservices on your laptop, the experience can feel like trying to rehearse a band in a closet: everything gets loud, resources spike, and the small tweaks you want to hear take forever. Docker Compose gives you two practical tools to simplify that rehearsal: service profiles (to run only the tracks you need) and Buildx Bake (to separate fast local builds from heavier production builds). Together they let you iterate quickly locally while keeping production builds robust and repeatable. (docs.docker.com)

Why separate dev runtime from production builds?

Local development benefits from speed and minimal friction: short rebuilds, a small set of services, hot-reload-friendly images. Production builds, on the other hand, often require multi-platform images, attestations, SBOMs, or different Dockerfile stages. If you try to fold everything into a single Compose workflow, you slow down the thing you care about most: fast iteration.

Docker’s recommended pattern is to keep Compose focused on local runtime and to use Buildx Bake (BuildKit) when you need production-grade build features. That way you reuse the same service definitions but avoid paying the time cost during daily development. (docs.docker.com)

Service profiles: turn your stack into playlists

Profiles let you tag services in your Compose file and only start the groups you need. Think of profiles like playlists: one for “core app”, one for “debug tools”, another for “integration tests”.

Example docker-compose.yml snippet:

services:
  api:
    build: ./api
    ports: ["8000:8000"]

  db:
    image: postgres:15
    environment:
      POSTGRES_PASSWORD: secret

  metrics:
    image: prom/prometheus
    profiles: ["monitoring"]

  admin:
    image: phpmyadmin
    depends_on: ["db"]
    profiles: ["debug"]

Tip: you can set COMPOSE_PROFILES to enable profiles from the environment if you prefer not to pass flags on every command. (docs.docker.com)

Bake with Buildx: production-ready image builds without slowing local iterations

Bake (docker buildx bake) reads build config from your Compose file and (optionally) a docker-bake.hcl to create a declarative build plan. You can:

Example docker-bake.hcl:

group "default" {
  targets = ["api", "worker"]
}

target "api" {
  context = "./api"
  dockerfile = "Dockerfile"
  target = "final"        # build production stage
  tags = ["example/api:stable"]
}

target "_common" {
  platforms = ["linux/amd64", "linux/arm64"]
  attest = ["type=sbom"]
}
target "worker" {
  inherits = ["_common"]
  context = "./worker"
  dockerfile = "Dockerfile"
  tags = ["example/worker:stable"]
}

Then run: docker buildx bake — this handles production-oriented options while leaving docker compose up fast for day-to-day work. (docs.docker.com)

The Compose project also added explicit support for using Buildx Bake with Compose, so this pattern is supported and maintained in the official tooling. (Bake integration was highlighted in Compose release notes.) (docs.docker.top)

Putting the two together: a simple workflow

You can also control build parallelism (to speed up CI or local Bake runs) using Compose/Buildx parallel options. Compose supports a –parallel flag and related environment variables to tune concurrency when pulling or building. (docs.docker.com)

Practical tips (mixing music metaphors with a little pragmatism)

Conclusion

Profiles and Buildx Bake together let you treat your microservice stack like both a rehearsal space and a recording studio: light and nimble while you iterate, and fully featured when you publish. The Compose tooling explicitly supports these patterns, so you get the convenience of Compose for local development and the power of BuildKit/Buildx for production builds—without turning everyday work into a long build session. (docs.docker.com)