Docker Run to Docker Compose Converter

Convert Docker Run Commands to Structured docker-compose.yml - Free & Private

Convert Your Docker Run Command

Supported flags: -d, -p, -e, -v, --name, --network, --restart, --cpus, --memory, --env-file, --label, --user, --workdir, --entrypoint, --cmd, --hostname, --add-host, --dns, --dns-search, --tmpfs, --shm-size, --ulimit, --cap-add, --cap-drop, --security-opt, --device, --gpus, --init, --rm, -it, -t, -i
Lines: - Size: -

What is Docker Run to Docker Compose Converter?

This tool converts complex docker run commands into structured, maintainable docker-compose.yml files. Whether you are migrating from ad-hoc container commands to production-ready compose files, sharing configurations with your team, or documenting your deployment, this converter eliminates the manual translation effort and prevents syntax errors that AI tools frequently introduce.

Docker Compose is the standard for defining multi-container applications. It provides version control, reproducibility, and declarative configuration that docker run commands lack. This converter bridges the gap by parsing your existing commands and generating spec-compliant YAML.

Why This Beats AI

Large language models (ChatGPT, Claude, Gemini) have critical failures when converting docker run to docker-compose:

  1. YAML indentation errors - Docker Compose is indentation-sensitive. AI models routinely produce misaligned YAML that docker-compose config rejects. A single space out of place breaks the entire file.
  2. Port mapping confusion - AI confuses -p 8080:80 (host:container) with Compose's "8080:80" format, often reversing the order or using wrong syntax like ports: [8080:80] without quotes.
  3. Volume syntax errors - Bind mounts (-v /host:/container) vs named volumes (-v name:/container) require different Compose syntax. AI mixes them incorrectly.
  4. Environment variable handling - AI loses --env-file references, expands variables incorrectly, or converts -e VAR=value to environment: {VAR: "value"} but forgets array vs object format differences.
  5. Restart policy mapping - --restart unless-stopped becomes restart: unless-stopped, but AI often writes restart: "unless-stopped" (string) or restart: always (wrong policy).
  6. Resource limits - --cpus and --memory map to deploy.resources.limits in Compose v3, but AI places them at the wrong nesting level.
  7. Network configuration - --network and --network-alias require networks section at top level. AI omits this or creates invalid references.

This tool uses deterministic parsing logic with zero AI involvement. Every flag is mapped to its correct Compose equivalent, indentation is always valid, and the output passes docker-compose config validation.

Features

  • Comprehensive flag support - Parses 30+ docker run flags including ports, volumes, env vars, networks, restart policies, resource limits, labels, and more
  • Compose version selection - Generate v3.8 (recommended), v3.9, or legacy v2.4 syntax
  • Custom service name - Set your preferred service name (default: app)
  • Optional comments - Include inline comments explaining each section
  • Alphabetical key sorting - Consistent key ordering for version control diffs
  • Sample templates - Load common patterns: web app, database, full stack, complex microservice
  • Download & copy - Save as .yml file or copy to clipboard
  • 100% client-side - Zero upload, zero server, zero API keys needed

Supported Docker Run Flags

Supported Docker Run Flags and Their Compose Mappings
Flag Description Compose Mapping
-p, --publishPort mappingports
-e, --envEnvironment variableenvironment
--env-fileEnv file pathenv_file
-v, --volumeVolume mountvolumes
--nameContainer namecontainer_name
--networkNetworknetworks
--restartRestart policyrestart
--cpusCPU limitdeploy.resources.limits.cpus
--memoryMemory limitdeploy.resources.limits.memory
--labelLabelslabels
--userUseruser
--workdirWorking directoryworking_dir
--entrypointEntrypointentrypoint
--hostnameHostnamehostname
--add-hostExtra hostsextra_hosts
--dnsDNS serversdns
--tmpfsTmpfs mountstmpfs
--shm-sizeShared memoryshm_size
--ulimitUlimitsulimits
--cap-add/--cap-dropCapabilitiescap_add/cap_drop
--security-optSecurity optionssecurity_opt
--deviceDevice mappingdevices
--gpusGPU accessdeploy.resources.reservations.devices
--initInit processinit
--rmAuto remove(not applicable in Compose)

Common Use Cases

  • Migration to Compose: Convert existing docker run commands from scripts, CI/CD, or documentation into version-controlled docker-compose.yml
  • Team Collaboration: Share container configurations declaratively instead of passing around complex command lines
  • Documentation: Generate Compose files for README examples, architecture docs, or onboarding guides
  • Production Hardening: Review and validate Compose output before deploying to staging/production
  • Learning Tool: Understand how docker run flags map to Compose syntax

How the Conversion Works

The parser tokenizes your docker run command using shell-aware splitting (respecting quotes and escapes). It then extracts each flag and its arguments, mapping them to the corresponding Docker Compose YAML structure. The generator produces spec-compliant YAML with proper indentation, array vs object formatting, and version-appropriate syntax.

For example, docker run -d -p 8080:80 -e NODE_ENV=production -v /data:/app/data --name webapp --restart unless-stopped nginx:alpine becomes:

version: "3.8"
services:
  app:
    image: nginx:alpine
    container_name: webapp
    ports:
      - "8080:80"
    environment:
      NODE_ENV: production
    volumes:
      - /data:/app/data
    restart: unless-stopped

Frequently Asked Questions

Does it handle multi-container docker run commands?

This tool converts a single docker run command to a single-service Compose file. For multi-container applications, convert each service separately and combine them manually, or use the generated file as a starting point for your full docker-compose.yml.

Is my command sent to a server?

No. All parsing and generation happens entirely within your browser. Your commands never leave your device. You can verify this by opening your browser's DevTools Network tab and observing zero outbound requests during conversion.

What if my command uses flags not listed?

The parser handles the most common 30+ flags. Unsupported flags are reported in the error output so you can add them manually. Open an issue on GitHub if you need a specific flag added.

Does it validate the generated YAML?

The generated YAML follows Docker Compose specification. You can validate it by running docker-compose config (or docker compose config) on the downloaded file.

Can it convert docker-compose.yml back to docker run?

Not currently. This tool focuses on the more common migration path: docker run to docker-compose. The reverse direction is less complex and more complex due to Compose features that don't have direct docker run equivalents.

Why should I use this instead of AI?

AI models frequently produce invalid YAML with broken indentation, incorrect port/volume syntax, wrong restart policy values, and misplaced resource limits. This tool uses deterministic parsing for 100% accurate, spec-compliant conversion every time. It works with commands of any complexity, has no usage limits, and never sends your data to an external server.

What Compose version should I choose?

Version 3.8 is recommended for most cases - it supports all modern features and works with Docker Compose v2 and Docker Engine 20.10+. Version 3.9 adds minor improvements. Version 2.4 is for legacy Swarm deployments only.

Comments & Ratings

Be the first to comment.

References