Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a compose.yaml file to define each microservice and its supporting services, then run the application with the Docker Compose CLI. Compose creates a shared network where services can normally reach one another by service name; healthchecks can keep dependent services from starting until a prerequisite is ready. For production, adapt the configuration to the host or cluster and plan separately for security, backups, monitoring, and capacity.

Model the application as Compose services

A Compose file is the source of truth for the services and supporting resources in a multi-container application. Each service can use a prebuilt image or build one from a directory, and can declare its environment, ports, volumes, networks, dependencies, healthcheck, restart behavior, and profile.

This small example defines an API and a PostgreSQL database. The API connects to the database using the service name db; the database uses a named volume so its data persists beyond the lifetime of an individual container.

services:
  api:
    build: ./api
    environment:
      DATABASE_URL: postgres://app:secret@db:5432/app
    depends_on:
      db:
        condition: service_healthy
    networks: [backend]

  db:
    image: postgres:18
    environment:
      POSTGRES_DB: app
      POSTGRES_USER: app
      POSTGRES_PASSWORD: secret
    volumes:
      - db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app -d app"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks: [backend]

networks:
  backend:

volumes:
  db-data:

The credentials here are illustrative, not a production secrets strategy. Replace them with appropriately managed production configuration before deployment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sandisk 2TB Extreme Portable SSD, Up to 1050MB/s, USB-C, USB 3.2 Gen 2, IP65 Water and Dust Resistance, Updated Firmware, External Solid State Drive, SDSSDE61-2T00-G25
  • Get NVMe solid state performance with up to 1050MB/s read and 1000MB/s write speeds in a portable, high-capacity drive(1) (Based on internal testing; performance may be lower depending on host device & other factors. 1MB=1,000,000 bytes.)
  • Up to 3-meter drop protection and IP65 water and dust resistance mean this tough drive can take a beating(3) (Previously rated for 2-meter drop protection and IP55 rating. Now qualified for the higher, stated specs.)
  • Use the handy carabiner loop to secure it to your belt loop or backpack for extra peace of mind.
  • Help keep private content private with the included password protection featuring 256‐bit AES hardware encryption.(3)
  • Easily manage files and automatically free up space with the SanDisk Memory Zone app.(5). Non-Operating Temperature -20°C to 85°C

Start, inspect, and operate the services

Run Compose commands from the directory containing compose.yaml. Compose creates and starts the declared application; its CLI also supports rebuilding, stopping, status inspection, logs, and one-off commands.

  1. docker compose up -d creates and starts the services in the background.
  2. docker compose ps inspects service status.
  3. docker compose logs -f api follows the API service logs.
  4. docker compose exec api sh opens a shell in a running API container, if the image includes a shell.
  5. docker compose down stops and removes the Compose application’s containers and network. Named volumes are retained unless explicitly removed, so do not add -v if you intend to keep the database data.

Use docker compose up --build when you need Compose to rebuild services that have a build configuration as it starts them. A one-off task, such as a migration, can be run with docker compose run --rm api <command>, substituting the actual command supported by the API image.

Make services communicate over the Compose network

When no explicit network is configured, Compose creates a default project network. Containers attached to the same Compose network can discover one another by service name. For example, an API can use http://orders:8080 to reach a service named orders, or connect to PostgreSQL at db:5432 as in the example.

Rank #2
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model)
  • Solid state performance with up to 800MB/s read speeds in a portable drive. (Based on internal testing; performance may be lower depending on host device, interface, usage conditions and other factors. 1MB=1,000,000 bytes.)
  • Back up your content and memories on a storage solution that fits seamlessly into your mobile lifestyle.
  • Take it with you on your adventures—up to two-meter drop protection means this durable drive can take a beating. (Based on internal testing.)
  • Secure it to your belt loop or backpack for extra peace of mind thanks to the tough rubber hook.
  • From Sandisk, a brand professional photographers trust to take on assignments.

Do not use localhost as the hostname for another container: from inside the API container, localhost refers to that API container itself. A published port is mainly for access from outside the Compose network; container-to-container traffic should use the service name and the port on which the destination service listens.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use separate networks when you want to limit which services can reach each other. An external network can connect services from separate Compose projects, but that network must already exist before you run docker compose up.

Handle startup order and readiness separately

depends_on establishes dependency creation order, but a running container is not necessarily ready to accept requests. If an API requires a database or broker to be ready first, give that prerequisite a meaningful healthcheck and use condition: service_healthy on the dependency, as the example does for PostgreSQL. Compose waits for the dependency’s healthcheck to pass before creating the dependent service.

Rank #3
Sale
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

Choose a check that tests the service’s actual readiness protocol or endpoint, not merely whether its process exists. Tune the healthcheck’s interval, timeout, retries, and—where appropriate—start period to the service’s startup behavior. Applications should also handle a dependency becoming unavailable after startup; a startup gate cannot guarantee ongoing availability.

Keep optional services in the same file with profiles

Services without a profiles entry are enabled by default. Put optional components—such as debugging tools, test services, migration helpers, or observability components—behind a named profile, then activate it when needed:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker compose --profile test up

A dependency reference does not automatically activate a service’s profile. If a service depends on a profiled service whose profile is inactive, Compose reports an error rather than silently enabling it. Check the profile design when an otherwise valid dependency is unavailable.

Rank #4
Sale
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model
  • NEARLY 2X FASTER THAN OUR PREVIOUS GENERATION(8) – move 1,000 high-res photos in under 60 seconds(6) with up to 2000MB/s transfer speeds(2).
  • IP65 RATING AND UP TO 3M DROP PROTECTION(3) – protects against spills and drops.
  • POCKET-SIZED – fits easily in pockets and small bags.
  • SPACE TO OWN YOUR AI CONTENT – speed and capacity to download your high-res clips and photo edits.
  • 256-BIT AES ENCRYPTION(4) – helps keep private files secure with password protection.

Separate development and production deliberately

One Compose file can describe the application’s core services and use profiles for optional components. That does not make development settings safe for production. Review configuration for the deployment environment, including application-code bind mounts, host port exposure, credentials, image versions, persistent data, restart behavior, and healthchecks.

  • Remove development-only bind mounts for application code from production configuration.
  • Set host ports and network exposure deliberately; publish only what must be reachable from outside the host.
  • Use production secrets and environment configuration rather than example credentials.
  • Pin image versions so deployments use an intentional image rather than an uncontrolled moving tag.
  • Back up named volumes that contain data the application needs to retain.
  • Choose restart and health behavior that fits the workload and the way the service is operated.

Compose is an operational control plane for the host or cluster where it is deployed. It does not replace capacity planning, observability, tested backups, or a decision about whether the deployment needs multiple-node orchestration.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Decide whether Compose fits the deployment

Docker’s production guidance covers deploying Compose on a single server and scaling Compose applications on a Swarm cluster. These are different operating choices: a single-server deployment keeps scheduling on one host, while a cluster changes where services can be scheduled and how operations are managed. Select based on the workload’s needs, not on an assumed universal scale limit.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
  • Easily store and access 5TB of content on the go with the Seagate portable drive, a USB external hard Drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

When comparing Compose with Swarm or Kubernetes, assess the capabilities and operational costs that matter to your application:

  • Single-host versus multi-node scheduling requirements.
  • Service discovery and networking across the intended deployment.
  • Rollout and rollback controls.
  • Secrets and configuration management.
  • Autoscaling requirements.
  • Observability integrations and operational ownership.
  • Storage behavior, including how persistent data is provisioned and recovered.
  • The team’s ability to operate the platform reliably.

There is no universal microservice count or performance threshold that determines when Compose stops being suitable. Measure latency, resource use, failure recovery, and deployment time on the target workload and host, then use those results to inform the deployment choice.

Quick Recap

Bestseller No. 2
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model)
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model)
From Sandisk, a brand professional photographers trust to take on assignments.
$188.90
SaleBestseller No. 3
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.99
SaleBestseller No. 4
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model
IP65 RATING AND UP TO 3M DROP PROTECTION(3) – protects against spills and drops.; POCKET-SIZED – fits easily in pockets and small bags.
$253.00
Bestseller No. 5
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$229.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.