DevOps

Docker Compose (JSON) JSON Example

A Docker Compose configuration as a JSON example — services, images, ports, environment, volumes, and depends_on. Copy-ready reference for multi-container app definitions.

{
  "services": {
    "web": {
      "image": "ghcr.io/acme/web:1.4.0",
      "ports": [
        "8080:8080"
      ],
      "environment": {
        "NODE_ENV": "production",
        "DATABASE_URL": "postgres://db:5432/app"
      },
      "depends_on": [
        "db"
      ],
      "restart": "unless-stopped"
    },
    "db": {
      "image": "postgres:16",
      "environment": {
        "POSTGRES_PASSWORD": "secret",
        "POSTGRES_DB": "app"
      },
      "volumes": [
        "pgdata:/var/lib/postgresql/data"
      ]
    }
  },
  "volumes": {
    "pgdata": {}
  }
}

Field Reference

servicesrequiredobjectMap of service name → service definition; each becomes a container
services.<name>.imageoptionalstringImage to run (or use 'build' to build from a Dockerfile)
services.<name>.portsoptionalarray<string>Port mappings as 'HOST:CONTAINER'
services.<name>.depends_onoptionalarray<string>Start order — these services start before this one
volumesoptionalobjectNamed volumes for persistent data shared across runs

Variants

Build from DockerfileBuild a service from local source instead of pulling an image.
Build from Dockerfile
{
  "services": {
    "api": {
      "build": {
        "context": "./api",
        "dockerfile": "Dockerfile"
      },
      "ports": [
        "3000:3000"
      ],
      "env_file": [
        ".env"
      ]
    }
  }
}

Common Use Cases

  • Defining a local multi-container dev environment
  • Documenting how an app's services fit together
  • Converting compose configuration between YAML and JSON
dockerdocker composecontainersdevopscompose

Validate or format this JSON

One click loads this exact example into the tool — no copy-paste needed. Format it, validate it, explore the tree, or generate TypeScript types instantly.

Frequently Asked Questions

Yes — Compose files are YAML, and since YAML is a superset of JSON, a valid JSON object with the same structure works too. The 'version' key is now optional in the Compose Specification, so a top-level 'services' map is enough.

By default it only controls start order, not readiness — the dependent service starts after the others start, but not necessarily after they're ready to accept connections. Add a healthcheck and 'condition: service_healthy' to wait for readiness.

Related JSON Examples