DevTools Logo

Docker Run to Compose Converter

Docker Run to Compose Converter

Turn a docker run command into a docker-compose.yml service definition

Input & Settings

2 spaces

About this tool

This tool parses a `docker run` command and emits an equivalent `docker-compose.yml` service definition. It maps the common flags — image, container name, published ports, volumes, environment variables, networks, restart policy, workdir, user, entrypoint, labels and command — to their Compose equivalents. The companion Docker Compose Builder (already in DevTools) goes the other direction visually. Use this when migrating one-off `docker run` invocations into a versioned Compose file. Parsing is client-side; no command is executed.

Examples & Use Cases

Web server with port mapping

# docker run command
docker run -d --name web -p 8080:80 nginx:latest

# docker-compose.yml
services:
  web:
    image: nginx:latest
    container_name: web
    ports:
      - "8080:80"

The container name becomes the service key; -p host:container maps to the ports list.

Database with env + volume

# docker run command
docker run -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=app -v pgdata:/var/lib/postgresql/data postgres:15

# docker-compose.yml
services:
  postgres:
    image: postgres:15
    environment:
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: app
    volumes:
      - pgdata:/var/lib/postgresql/data

Environment flags become a key/value map; named volumes map to the volumes list.

Restart policy + network

# docker run command
docker run --restart unless-stopped --network mynet redis:7

# docker-compose.yml
services:
  redis:
    image: redis:7
    networks:
      - mynet
    restart: unless-stopped

--restart maps to the restart field; --network maps to the networks list.

    Examples

    Convert a basic nginx run command

    Input
    docker run -d --name web -p 8080:80 nginx:latest
    Output
    services:
      web:
        image: nginx:latest
        container_name: web
        ports:
          - "8080:80"
        restart: "no"
        command: []

    The container name, published port mapping, and image tag are all mapped. The -d flag is noted; restart defaults to 'no' since no --restart flag was given.

    Convert a command with volumes and environment

    Input
    docker run -d --name db -v pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=secret --restart always postgres:16
    Output
    services:
      db:
        image: postgres:16
        container_name: db
        environment:
          - POSTGRES_PASSWORD=secret
        volumes:
          - pgdata:/var/lib/postgresql/data
        restart: always
    volumes:
      pgdata:

    The named volume pgdata is detected and the builder adds it to the top-level volumes: block. Bind mounts (./data:/app/data) are left as-is and not added to volumes:.

    About this tool

    Docker Run to Compose Converter takes a docker run command and emits a corresponding docker-compose.yml service definition. It parses the command using a quote-aware tokenizer so complex arguments — those containing spaces, equals signs, or multiple flags — are handled correctly before being mapped to their compose equivalents.

    Mapped flags include --name, -p (publish), -v (volume), -e (environment), --restart, --network, -w (workdir), -u (user), --entrypoint, -l (label), --hostname, and the trailing command. Named volumes are automatically collected into the top-level volumes: block.

    The YAML is generated entirely in your browser using js-yaml — no docker command is executed and nothing is uploaded.

    How to use this tool

    1. Paste a docker run command

      Enter or paste a docker run command into the input. The tokenizer handles quoted arguments and complex flag combinations.

    2. Review the generated YAML

      The output shows a docker-compose.yml service block, with named volumes gathered into the top-level volumes: section automatically.

    3. Copy or download

      Copy the YAML or download docker-compose.yml, then run docker compose up to start the service.

    Use cases

    Migrating a docker run script to Compose

    Take an existing shell script full of docker run commands and convert each one into a Compose service, making the stack reproducible with docker compose up.

    Documenting how a container was started

    Capture the exact flags used to run a container as a Compose definition that can be committed to version control alongside the Dockerfile.

    Quick Compose scaffolding

    Sketch out a Compose service by typing the docker run command you already know, then refine the generated YAML in the editor.

    Common mistakes

    Mistake:Omitting quotes around port mappings with a host port.

    Fix:YAML interprets 8080:80 as the number 42240 (8080 / 0.191). The builder quotes port strings automatically, but if you edit the output, always quote host:container mappings.

    Mistake:Using a bind mount path as a named volume.

    Fix:./data:/app/data is a bind mount (host path). data:/app/data is a named volume. The builder detects leading ./ as a bind mount and omits it from volumes:; named volumes are added automatically.

    Frequently asked questions

    What does the converter do?

    It takes a docker run command and emits a docker-compose.yml service definition. The command is parsed with a quote-aware tokenizer so complex arguments — those containing spaces, equals signs, or multiple flags — are handled correctly before being mapped to their compose equivalents.

    Which flags are mapped?

    The tool maps --name, -p (publish), -v (volume), -e (environment), --restart, --network, -w (workdir), -u (user), --entrypoint, -l (label), --hostname, and the trailing command. Port mappings are quoted so values like 8080:80 are not misread as arithmetic.

    Can it convert multi-service commands?

    The tool converts a single container invocation at a time. For a multi-container stack, run the tool separately for each docker run command and merge the resulting service blocks into one docker-compose.yml.

    Is my command sent to a server?

    No. Tokenization and YAML generation run entirely in your browser with js-yaml. The command you type is never transmitted.

    References & standards

    .env Secret Safety Linter

    Validate .env syntax and spot likely leaked credentials or placeholder secrets.

    .htaccess Generator

    Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth

    2D Fluid Dynamics & Particle Physics Sandbox

    A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.

    AI Function Calling Schema Generator

    Generate function calling JSON schemas from TypeScript interfaces

    Algorithm Arena & Data Structure Visualizer

    Interactive arena for algorithms and data structures: eight sorting algorithms racing on one seeded input, six pathfinding algorithms walking generated mazes, and BST, AVL, Red-Black, B-tree, heap and trie operations replayed step by step with rotations highlighted. Every run shows the Big-O table and the phase-highlighted reference implementation in four languages, and compared values can be played as pitch (sonification) through the shared audio engine. Everything runs client-side; inputs never leave the browser.

    Ansible Playbook Generator

    Build an Ansible playbook — hosts, vars, and tasks with modules — as YAML