Generated banner for Docker Compose Patterns
Generated logo for Docker Compose Patterns

Docker Compose Patterns

DockerOfficialPublished by Docker

  • Skill
  • Tool integration
  • Cloud and DevOps
  • Apache-2.0
  • Low risk
  • Has scripts

From the author

Use this skill when creating, modifying, or debugging Docker Compose configurations, even if the user just says they need to wire services together, add a database to their stack, or set up a local development environment with multiple containers. Covers service definitions, health checks, dependency ordering, volumes, networks, environment variables, and development overrides.
— the description by Docker

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured approach to managing multi-container environments using Docker Compose. It focuses on best practices for service definitions, dependency management, health checks, and environment configuration to ensure reliable local development and service orchestration. It emphasizes the use of modern Compose v2 features while providing guardrails for destructive commands and complex networking scenarios.

What it does

  • Defines standardized service configurations and naming conventions.
  • Implements robust health checks for infrastructure services like databases.
  • Manages service startup dependencies using health-aware conditions.
  • Provides patterns for volume management and network isolation.
  • Guides the use of development overrides and Compose Watch for efficient workflows.
  • Includes safety guardrails for destructive commands like volume deletion.

When to use it

  • When creating a new compose.yaml file for a multi-service application.
  • When adding new services or databases to an existing stack.
  • When troubleshooting service connectivity or startup ordering issues.
  • When setting up development-specific overrides or file-syncing workflows.
  • When needing to ensure data persistence across container restarts.

Advantages

  • Reduces configuration errors through standardized patterns.
  • Improves service reliability by ensuring dependencies are actually ready.
  • Prevents accidental data loss with clear guidance on destructive commands.
  • Promotes clean, maintainable infrastructure-as-code practices.
  • Provides specific solutions for complex scenarios like distroless image health checks.

Usage examples

“How do I make sure my web service waits for the database to be ready before starting?”
The agent will recommend using the depends_on key with the condition: service_healthy attribute, alongside a proper healthcheck definition for the database service.
“I need to add a Postgres database to my project, what is the best way to handle the data?”
The agent will provide a configuration using a named volume to ensure data persistence and suggest adding a healthcheck to the database service.
“How can I sync my local source code changes to the container without rebuilding?”
The agent will explain how to use the develop.watch configuration in your compose.yaml to enable file syncing.
“I want to clean up my project, can I run docker compose down -v?”
The agent will warn you that this command deletes named volumes and data, and will ask for explicit confirmation before proceeding.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/docker/docker-compose-patterns/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip docker-compose-patterns.zip -d .agents/skills

Documentation by Docker

Docker Compose Patterns

Overview

This skill provides rules for creating, reviewing, and debugging Docker Compose configurations. Use it when the main artifact is compose.yaml or compose.override.yaml and the task is about service wiring rather than image-build internals.

When to use this skill

Activate this skill when:

  • Creating a new compose.yaml for a project

  • Adding or modifying services in an existing Compose file

  • Setting up development overrides with compose.override.yaml

  • Debugging service startup ordering or connectivity issues

Do not use this skill when

Do not use this skill when:

  • The project has no Docker setup yet and the main need is an initial scaffold

  • The main task is writing or optimizing a Dockerfile

  • The main task is improving build caching, image size, or runtime user configuration

Core guidance

File naming

Use compose.yaml as the canonical filename. Do not use docker-compose.yml or docker-compose.yaml — those are legacy names.

Service definitions
  • Give services clear, lowercase names that reflect their role: web, db, cache, worker.

  • Always pin image tags to a specific version. Never use latest or omit the tag.

  • Set restart: unless-stopped for long-running infrastructure services and non-development deployments.

  • Add container_name only when external tools need a predictable name. Otherwise, let Compose generate names.

Dependency modeling
  • Use depends_on with condition: service_healthy for services that must be ready before dependents start.

  • Every service listed in depends_on with a health condition must have a healthcheck defined.

  • Do not rely on depends_on without conditions — it only guarantees container start, not readiness.

Health checks
  • Always add a healthcheck to database services (Postgres, MySQL, Redis, MongoDB).

  • Use the service's native client tool for health checks when available (e.g., pg_isready, redis-cli ping, mysqladmin ping).

  • Set reasonable interval, timeout, retries, and start_period values. Start with: interval: 5s, timeout: 3s, retries: 3, start_period: 10s.

Health checks for distroless or scratch images

Distroless, scratch-based, and hardened images contain no shell, curl, or wget. Do not bake tools into these images — that defeats their purpose. Instead, use a healthcheck sidecar that shares the application's network namespace:

services:
  api:
    build:
      context: .
      target: runtime          # distroless / hardened image
    ports:
      - "8080:8080"
    # No healthcheck here — the image has no tools to run one

  api-health:
    image: curlimages/curl:8.22.0
    network_mode: "service:api"   # shares api's localhost
    entrypoint: ["sleep", "infinity"]  # keep sidecar alive for healthcheck
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 45s
    deploy:
      resources:
        limits:
          memory: 32M

Key points:

  • The sidecar must stay alive with entrypoint: ["sleep", "infinity"] so Compose can execute the healthcheck inside it.

  • network_mode: "service:api" makes localhost inside the sidecar resolve to the api container's loopback — no extra networking needed.

  • Keep the sidecar lightweight with a resource limit (32MB is sufficient for curl).

  • Services that depend on api being ready should reference the sidecar, not the api directly:

  worker:
    depends_on:
      api-health:
        condition: service_healthy
Volumes
  • Use named volumes for data that must persist across container recreations (database data, uploaded files).

  • Use bind mounts only for development-time source code syncing.

  • Define all named volumes in the top-level volumes: key.

  • Do not mount the Docker socket unless the service genuinely requires it.

Networks
  • For single-application stacks, the default network is sufficient. Do not create custom networks unless you need isolation between service groups.

  • When creating custom networks, prefer bridge driver and give networks descriptive names.

  • Use the top-level networks: key to define all custom networks.

Environment variables
  • Use environment: for non-sensitive values that are few in number.

  • Use env_file: pointing to a .env file for longer lists of variables.

  • Never hardcode secrets (passwords, API keys) directly in compose.yaml. Use env_file: or Docker secrets.

  • When defaults are needed in the environment: block for local development, use variable substitution with fallbacks: ${DB_PASSWORD:-postgres}. Never write bare plaintext values for password fields.

  • Add .env to .gitignore.

Development overrides
  • Use compose.override.yaml for development-only settings. Compose loads it automatically alongside compose.yaml.

  • Put bind mounts for source code, debug ports, and development environment variables in the override file.

  • Use develop.watch for file-syncing and auto-rebuild in development when supported.

  • Keep production-oriented settings in the base compose.yaml and override only what changes for development.

Compose Watch
  • Prefer develop.watch over manual bind mounts for development workflows.

  • Use action: sync for files that should be copied into the container on change (source code).

  • Use action: rebuild for files that require a full image rebuild (dependency files like package.json, requirements.txt).

  • Use action: sync+restart for configuration files that need a process restart.

Destructive commands

Some Compose commands delete data irreversibly. Before running any of the following, state exactly which data will be deleted and get explicit confirmation from the user — do not run them as a side effect of debugging, restarting, or "cleaning up" a stack:

  • docker compose down -v / docker compose down --volumes — deletes named volumes, including database data.

  • docker volume rm / docker volume prune run against a Compose project's volumes — deletes volumes directly. For the standalone case (no Compose project in play), see docker-destructive-guardrails instead. A volume referenced via external: true isn't managed by the Compose project either (down -v won't touch it) — treat it as the standalone case too: run docker volume rm without -f first, and get explicit confirmation before deleting it.

  • docker compose rm -v — deletes anonymous volumes attached to removed containers.

If the goal is only to restart services or reclaim containers/networks, use docker compose down (no -v) or docker compose restart instead — these leave named volumes intact.

  • For first-time Docker project scaffolding and baseline file creation, use docker-project-foundations.

  • For Dockerfile internals, build caching, multi-stage builds, and .dockerignore, use docker-build-strategies.

  • For destructive Docker CLI commands outside Compose (docker system prune, docker rm -f, image/network/builder pruning, standalone volume deletion) and a cross-product index of destructive-command guardrails, use docker-destructive-guardrails.

References

  • references/service-dependencies.md — Detailed guidance on depends_on, health check patterns for common databases, and startup ordering strategies.

  • references/volumes-and-networks.md — Patterns for volume mounts, named volumes, bind mounts, and network configuration.

Assets

  • assets/compose-web-app.yaml — Complete multi-service web app (app + Postgres + Redis) with health checks, dependencies, and named volumes.

  • assets/compose-dev-override.yaml — Development override showing bind mounts, debug ports, and Compose Watch configuration.

  • assets/bad-vs-good.md — Before/after comparisons of common Compose mistakes and their fixes.

Scripts

  • scripts/verify-compose.sh — Validates the Compose project in the current directory with docker compose config --quiet, without printing resolved configuration. Run it from the project root (the directory that contains compose.yaml), with the script path resolved under this skill's directory:

    bash "<skill-dir>/scripts/verify-compose.sh" [--help]

    Replace <skill-dir> with the absolute path of the folder that contains this SKILL.md; the scripts/ path is relative to that folder, not to the project. Do not change into the skill directory first: the script validates whatever Compose project is in the current directory. If the skill directory cannot be resolved, run docker compose config --quiet directly. Exit status is 0 when the Compose configuration is valid or help is requested, the non-zero status from docker compose config --quiet when validation fails, and 2 for invalid arguments. Plain docker compose config can expose interpolated and env_file credentials in tool output or logs; use quiet validation by default. Compose warnings and errors are still emitted and may contain sensitive details.

Checks

  • checks/verification.md — Detailed verification runbook for manual review.

Files

LICENSE


                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright 2026 Docker, Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs network access, Needs an API key

The author says: Requires Docker Compose v2 (compose.yaml format).

Security

What our scanner noticed· Low risk

  • Instructions that use the network
  • Scripts that your agent may run

This skill includes scripts that your agent may run. Read them before you use it.

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
Docker
Publisher
Docker (Official)
Source
docker/skills · skills/docker-compose-patterns · commit 9f04a05
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Docker or Docker.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download docker-compose-patterns.zip