Docker Compose Generator

Writing a docker-compose.yml by hand means remembering the exact indentation, quoting every port mapping, and knowing which version string your Compose binary understands. This generator lets you define services through simple fields: a name, an image, host:container port mappings and volumes. It outputs a valid YAML file with the modern Compose spec (no version key) and sensible defaults.

How to build a Compose file

  1. 1

    Add services

    Set a name, an image, host:container port mappings and volumes for each service. Two starter services are already filled in.

  2. 2

    Adjust or remove rows

    Edit any field directly, add another service with the + Service button, or remove a row you do not need.

  3. 3

    Check the generated YAML

    The preview updates as you type: port mappings are quoted and the version key is omitted, as the modern Compose spec expects.

  4. 4

    Copy the file

    Copy the generated docker-compose.yml and paste it into your project root.

The modern Compose spec

Compose V2 (the plugin shipped with Docker Desktop and modern Docker Engine) follows the Compose Specification. The version: key is deprecated; the generator omits it. Top-level keys are services, networks, volumes, configs and secrets.

Service anatomy

A production-leaning service looks like this:

services:
  web:
    image: nginx:1.27-alpine
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      - ./public:/usr/share/nginx/html:ro
    depends_on:
      app:
        condition: service_healthy
    networks:
      - frontend
      - backend
    healthcheck:
      test: ["CMD", "wget", "--spider", "-q", "http://localhost/health"]
      interval: 30s
      timeout: 5s
      retries: 3

Volumes: bind mount vs named

  • Bind mount (./app:/var/www) ties the container to a path on the host; great for local development because changes reflect immediately.
  • Named volume (pgdata:/var/lib/postgresql/data) is managed by Docker and persists independent of any host path; the right choice for databases and anything you do not want to delete accidentally with rm -rf.
  • Anonymous volume - avoid. It survives restarts but disappears on docker compose down -v without warning.

Networks

By default Compose creates a network named after the project and connects every service to it. Declaring explicit networks is useful when:

  • You want to isolate a database from a public-facing service.
  • You need a bridge with a custom subnet to align with existing infrastructure.
  • You want to attach containers to a pre-existing external network (external: true).

Common mistakes to avoid

  • Version key conflicts. version: "3.8" at the top prevents newer features like healthcheck start_interval from working in old Compose; the generator omits the version key.
  • Port quoting. 8080:80 parses as YAML base-60 in some edge cases; the generator always quotes port mappings.
  • Hard-coded secrets. Secrets written directly into compose.yml end up committed to git. Keep them in an env_file or in the platform’s secret store instead.
  • depends_on without condition. Plain depends_on: [db] waits for the container to start, not the service to be ready. Use condition: service_healthy and add a healthcheck to the dependency.

Frequently Asked Questions

The current Compose Specification (aligned with Docker Compose V2). The file omits the version: key, which is how modern Compose files are written. It works with Docker Compose V2.22 and newer.

Not through the form in this version. The generator focuses on service definitions with image, ports and volumes. You can add networks, environment variables, health checks and other keys to the generated YAML by hand before using it.

No, this tool focuses on compose.yml. For Dockerfiles, use the Dockerfile Generator, which handles the base image choice and the COPY/RUN ordering for five stacks.

No. The service definitions are used only to build the YAML on this page. They are not stored, uploaded or shared.

Related Tools

Tool available in other languages