{
    "url": "https://delaparra-services.nl/skills/docker-compose-patterns",
    "locale": "en",
    "title": "Docker Compose Patterns | DeLaParra Services",
    "description": "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.",
    "alternates": {
        "en": "https://delaparra-services.nl/skills/docker-compose-patterns",
        "nl": "https://delaparra-services.nl/nl/skills/docker-compose-patterns"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/skills/docker-compose-patterns.csv",
        "md": "https://delaparra-services.nl/skills/docker-compose-patterns.md",
        "json": "https://delaparra-services.nl/skills/docker-compose-patterns.json",
        "zip": "https://delaparra-services.nl/skills/docker-compose-patterns.zip",
        "pdf": "https://delaparra-services.nl/skills/docker-compose-patterns.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/skills/docker-compose-patterns.csv",
            "encodingFormat": "text/csv",
            "name": "docker-compose-patterns.csv"
        },
        {
            "url": "https://delaparra-services.nl/skills/docker-compose-patterns.json",
            "encodingFormat": "application/json",
            "name": "docker-compose-patterns.json"
        },
        {
            "url": "https://delaparra-services.nl/skills/docker-compose-patterns.md",
            "encodingFormat": "text/markdown",
            "name": "docker-compose-patterns.md"
        },
        {
            "url": "https://delaparra-services.nl/skills/docker-compose-patterns.pdf",
            "encodingFormat": "application/pdf",
            "name": "docker-compose-patterns.pdf"
        },
        {
            "url": "https://delaparra-services.nl/skills/docker-compose-patterns.zip",
            "encodingFormat": "application/zip",
            "name": "docker-compose-patterns.zip"
        },
        {
            "url": "https://delaparra-services.nl/skills/docker-compose-patterns/download",
            "encodingFormat": "application/zip",
            "name": "docker-compose-patterns-files.zip"
        }
    ],
    "markdown": "# Docker Compose Patterns\n\n \n\nUse 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.\n\n \n\n**Licence** Apache-2.0\n\n \n\n**Source** docker/skills\n\n \n\n**This skill contains executable scripts.**\n\n [Download zip](<https://delaparra-services.nl/skills/docker-compose-patterns/download>)   \n\n# Docker Compose Patterns\n\n \n\n## Overview\n\n \n\nThis 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.\n\n \n\n## When to use this skill\n\n \n\nActivate this skill when:\n\n \n\n- Creating a new ` compose.yaml ` for a project \n- Adding or modifying services in an existing Compose file \n- Setting up development overrides with ` compose.override.yaml ` \n- Debugging service startup ordering or connectivity issues\n\n \n\n## Do not use this skill when\n\n \n\nDo not use this skill when:\n\n \n\n- The project has no Docker setup yet and the main need is an initial scaffold \n- The main task is writing or optimizing a ` Dockerfile ` \n- The main task is improving build caching, image size, or runtime user configuration\n\n \n\n## Core guidance\n\n \n\n### File naming\n\n \n\nUse ` compose.yaml ` as the canonical filename. Do not use ` docker-compose.yml ` or ` docker-compose.yaml ` — those are legacy names.\n\n \n\n### Service definitions\n\n \n\n- Give services clear, lowercase names that reflect their role: ` web `, ` db `, ` cache `, ` worker `. \n- Always pin image tags to a specific version. Never use ` latest ` or omit the tag. \n- Set ` restart: unless-stopped ` for long-running infrastructure services and non-development deployments. \n- Add ` container_name ` only when external tools need a predictable name. Otherwise, let Compose generate names.\n\n \n\n### Dependency modeling\n\n \n\n- Use ` depends_on ` with ` condition: service_healthy ` for services that must be ready before dependents start. \n- Every service listed in ` depends_on ` with a health condition must have a ` healthcheck ` defined. \n- Do not rely on ` depends_on ` without conditions — it only guarantees container start, not readiness.\n\n \n\n### Health checks\n\n \n\n- Always add a ` healthcheck ` to database services (Postgres, MySQL, Redis, MongoDB). \n- Use the service's native client tool for health checks when available (e.g., ` pg_isready `, ` redis-cli ping `, ` mysqladmin ping `). \n- Set reasonable ` interval `, ` timeout `, ` retries `, and ` start_period ` values. Start with: ` interval: 5s `, ` timeout: 3s `, ` retries: 3 `, ` start_period: 10s `.\n\n \n\n#### Health checks for distroless or scratch images\n\n \n\nDistroless, 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:\n\n \n\n```\nservices:\n  api:\n    build:\n      context: .\n      target: runtime          # distroless / hardened image\n    ports:\n      - \"8080:8080\"\n    # No healthcheck here — the image has no tools to run one\n\n  api-health:\n    image: curlimages/curl:8.22.0\n    network_mode: \"service:api\"   # shares api's localhost\n    entrypoint: [\"sleep\", \"infinity\"]  # keep sidecar alive for healthcheck\n    healthcheck:\n      test: [\"CMD\", \"curl\", \"-f\", \"http://localhost:8080/health\"]\n      interval: 30s\n      timeout: 5s\n      retries: 3\n      start_period: 45s\n    deploy:\n      resources:\n        limits:\n          memory: 32M\n```\n\n \n\nKey points:\n\n \n\n- The sidecar must stay alive with ` entrypoint: [\"sleep\", \"infinity\"] ` so Compose can execute the healthcheck inside it. \n- ` network_mode: \"service:api\" ` makes ` localhost ` inside the sidecar resolve to the api container's loopback — no extra networking needed. \n- Keep the sidecar lightweight with a resource limit (32MB is sufficient for curl). \n- Services that depend on ` api ` being ready should reference the **sidecar**, not the api directly:\n\n \n\n```\n  worker:\n    depends_on:\n      api-health:\n        condition: service_healthy\n```\n\n \n\n### Volumes\n\n \n\n- Use named volumes for data that must persist across container recreations (database data, uploaded files). \n- Use bind mounts only for development-time source code syncing. \n- Define all named volumes in the top-level ` volumes: ` key. \n- Do not mount the Docker socket unless the service genuinely requires it.\n\n \n\n### Networks\n\n \n\n- For single-application stacks, the default network is sufficient. Do not create custom networks unless you need isolation between service groups. \n- When creating custom networks, prefer bridge driver and give networks descriptive names. \n- Use the top-level ` networks: ` key to define all custom networks.\n\n \n\n### Environment variables\n\n \n\n- Use ` environment: ` for non-sensitive values that are few in number. \n- Use ` env_file: ` pointing to a ` .env ` file for longer lists of variables. \n- Never hardcode secrets (passwords, API keys) directly in ` compose.yaml `. Use ` env_file: ` or Docker secrets. \n- 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. \n- Add ` .env ` to ` .gitignore `.\n\n \n\n### Development overrides\n\n \n\n- Use ` compose.override.yaml ` for development-only settings. Compose loads it automatically alongside ` compose.yaml `. \n- Put bind mounts for source code, debug ports, and development environment variables in the override file. \n- Use ` develop.watch ` for file-syncing and auto-rebuild in development when supported. \n- Keep production-oriented settings in the base ` compose.yaml ` and override only what changes for development.\n\n \n\n### Compose Watch\n\n \n\n- Prefer ` develop.watch ` over manual bind mounts for development workflows. \n- Use ` action: sync ` for files that should be copied into the container on change (source code). \n- Use ` action: rebuild ` for files that require a full image rebuild (dependency files like ` package.json `, ` requirements.txt `). \n- Use ` action: sync+restart ` for configuration files that need a process restart.\n\n \n\n### Destructive commands\n\n \n\nSome 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:\n\n \n\n- ` docker compose down -v ` / ` docker compose down --volumes ` — deletes named volumes, including database data. \n- ` 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. \n- ` docker compose rm -v ` — deletes anonymous volumes attached to removed containers.\n\n \n\nIf 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.\n\n \n\n## Related skills\n\n \n\n- For first-time Docker project scaffolding and baseline file creation, use ` docker-project-foundations `. \n- For Dockerfile internals, build caching, multi-stage builds, and ` .dockerignore `, use ` docker-build-strategies `. \n- 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 `.\n\n \n\n## References\n\n \n\n- ` references/service-dependencies.md ` — Detailed guidance on ` depends_on `, health check patterns for common databases, and startup ordering strategies. \n- ` references/volumes-and-networks.md ` — Patterns for volume mounts, named volumes, bind mounts, and network configuration.\n\n \n\n## Assets\n\n \n\n- ` assets/compose-web-app.yaml ` — Complete multi-service web app (app + Postgres + Redis) with health checks, dependencies, and named volumes. \n- ` assets/compose-dev-override.yaml ` — Development override showing bind mounts, debug ports, and Compose Watch configuration. \n- ` assets/bad-vs-good.md ` — Before/after comparisons of common Compose mistakes and their fixes.\n\n \n\n## Scripts\n\n \n\n- **` 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: \n\n```\nbash \"<skill-dir>/scripts/verify-compose.sh\" [--help]\n```\n\n 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.\n\n \n\n## Checks\n\n \n\n- ` checks/verification.md ` — Detailed verification runbook for manual review.\n\n \n\n## Files\n\n \n\n- ` LICENSE ` \n- ` SKILL.md ` \n- ` SOURCE.md ` \n- ` agents/openai.yaml ` \n- ` assets/bad-vs-good.md ` \n- ` assets/compose-dev-override.yaml ` \n- ` assets/compose-web-app.yaml ` \n- ` checks/verification.md ` \n- ` evals/docker-compose-patterns.md ` \n- ` references/service-dependencies.md ` \n- ` references/volumes-and-networks.md ` \n- ` scripts/verify-compose.sh ` \n- ` skill.yaml `\n\n \n\n## Related terms\n\n \n\n- [anonymous volume](<https://delaparra-services.nl/knowledge-hub/anonymous-volume>) \n- [bind mount](<https://delaparra-services.nl/knowledge-hub/bind-mount>) \n- [bridge](<https://delaparra-services.nl/knowledge-hub/bridge>) \n- [ConnectionRefused](<https://delaparra-services.nl/knowledge-hub/connectionrefused>) \n- [container](<https://delaparra-services.nl/knowledge-hub/container>) \n- [container DNS](<https://delaparra-services.nl/knowledge-hub/container-dns>) \n- [Containerisation](<https://delaparra-services.nl/knowledge-hub/containerisation>) \n- [Daemon](<https://delaparra-services.nl/knowledge-hub/daemon>) \n- [depends\\_on](<https://delaparra-services.nl/knowledge-hub/depends-on>) \n- [digest](<https://delaparra-services.nl/knowledge-hub/digest>) \n- [Docker Hub](<https://delaparra-services.nl/knowledge-hub/docker-hub>) \n- [ENV](<https://delaparra-services.nl/knowledge-hub/env>) \n- [environment](<https://delaparra-services.nl/knowledge-hub/environment>) \n- [EXPOSE](<https://delaparra-services.nl/knowledge-hub/expose>) \n- [HEALTHCHECK](<https://delaparra-services.nl/knowledge-hub/healthcheck>) \n- [healthcheck (compose)](<https://delaparra-services.nl/knowledge-hub/healthcheck-compose>) \n- [host](<https://delaparra-services.nl/knowledge-hub/host>) \n- [networks (compose)](<https://delaparra-services.nl/knowledge-hub/networks-compose>) \n- [none](<https://delaparra-services.nl/knowledge-hub/none>) \n- [PermissionDenied](<https://delaparra-services.nl/knowledge-hub/permissiondenied>) \n- [port mapping](<https://delaparra-services.nl/knowledge-hub/port-mapping>) \n- [ports](<https://delaparra-services.nl/knowledge-hub/ports>) \n- [pull](<https://delaparra-services.nl/knowledge-hub/pull>) \n- [push](<https://delaparra-services.nl/knowledge-hub/push>) \n- [registry](<https://delaparra-services.nl/knowledge-hub/registry>) \n- [RUN](<https://delaparra-services.nl/knowledge-hub/run>) \n- [services](<https://delaparra-services.nl/knowledge-hub/services>) \n- [tag](<https://delaparra-services.nl/knowledge-hub/tag>) \n- [tag-and-push](<https://delaparra-services.nl/knowledge-hub/tag-and-push>) \n- [tmpfs](<https://delaparra-services.nl/knowledge-hub/tmpfs>) \n- [Virtual machine](<https://delaparra-services.nl/knowledge-hub/virtual-machine>) \n- [VOLUME](<https://delaparra-services.nl/knowledge-hub/volume>) \n- [volumes (compose)](<https://delaparra-services.nl/knowledge-hub/volumes-compose>)\n\n \n\n[Installing an agent skill in Claude Code, Codex, Cursor and Copilot](<https://delaparra-services.nl/manuals/een-skill-installeren-in-je-ai-assistent>)\n\n[HTML version](https://delaparra-services.nl/skills/docker-compose-patterns)\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "Organization",
                "@id": "https://delaparra-services.nl/#practice",
                "logo": "https://delaparra-services.nl/logo.png",
                "name": "DeLaParra Services",
                "legalName": "DeLaParra Services",
                "url": "https://delaparra-services.nl/",
                "description": "Bespoke software, web applications and mobile apps, developed in Laravel by a single developer in Groningen. Fixed price agreed in advance, full source code provided upon delivery.",
                "email": "info@delaparra-services.nl",
                "address": {
                    "@type": "PostalAddress",
                    "addressLocality": "Groningen",
                    "addressRegion": "Groningen",
                    "addressCountry": "NL"
                },
                "areaServed": "Groningen, the Netherlands",
                "knowsLanguage": [
                    "en",
                    "nl"
                ],
                "knowsAbout": [
                    "Web design and development",
                    "App development",
                    "Custom software and web applications",
                    "OpenSpec",
                    "AI code review",
                    "Your own coding agent"
                ],
                "founder": {
                    "@id": "https://delaparra-services.nl/#person"
                }
            },
            {
                "@type": "WebPage",
                "@id": "https://delaparra-services.nl/skills/docker-compose-patterns#webpage",
                "url": "https://delaparra-services.nl/skills/docker-compose-patterns",
                "name": "Docker Compose Patterns | DeLaParra Services",
                "description": "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.",
                "isPartOf": {
                    "@id": "https://delaparra-services.nl/#website"
                },
                "about": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "inLanguage": "en",
                "breadcrumb": {
                    "@id": "https://delaparra-services.nl/skills/docker-compose-patterns#breadcrumb"
                }
            },
            {
                "@type": "BreadcrumbList",
                "@id": "https://delaparra-services.nl/skills/docker-compose-patterns#breadcrumb",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "name": "Home",
                        "item": "https://delaparra-services.nl/"
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "name": "Docker Compose Patterns"
                    }
                ]
            },
            {
                "@type": "Person",
                "@id": "https://delaparra-services.nl/#person",
                "name": "Reinier de la Parra",
                "url": "https://delaparra-services.nl/about"
            },
            {
                "@type": "SoftwareSourceCode",
                "@id": "https://delaparra-services.nl/skills/docker-compose-patterns#skill",
                "url": "https://delaparra-services.nl/skills/docker-compose-patterns",
                "name": "Docker Compose Patterns",
                "description": "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.",
                "inLanguage": "en",
                "license": "https://spdx.org/licenses/Apache-2.0.html",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/skills/docker-compose-patterns#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/skills/docker-compose-patterns#dataset",
                "name": "Docker Compose Patterns",
                "description": "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.",
                "url": "https://delaparra-services.nl/skills/docker-compose-patterns",
                "identifier": "https://delaparra-services.nl/skills/docker-compose-patterns#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/skills/docker-compose-patterns#skill"
                },
                "creditText": "docker/skills",
                "publisher": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "license": "https://spdx.org/licenses/Apache-2.0.html",
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "dateModified": "2026-11-28T14:00:11+00:00",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/knowledge-hub#skills",
                    "name": "Skills for AI coding assistants",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "docker-compose-patterns.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/skills/docker-compose-patterns.csv",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/Apache-2.0.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "docker-compose-patterns.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/skills/docker-compose-patterns.json",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/Apache-2.0.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "docker-compose-patterns.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/skills/docker-compose-patterns.md",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/Apache-2.0.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "docker-compose-patterns.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/skills/docker-compose-patterns.pdf",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/Apache-2.0.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "docker-compose-patterns.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/docker-compose-patterns.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/Apache-2.0.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "docker-compose-patterns-files.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/docker-compose-patterns/download",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/Apache-2.0.html"
                    }
                ]
            }
        ]
    }
}