Skip to main content

Docker Run to Docker Compose Converter

Convert CLI docker run commands to clean docker-compose.yml files

Sample Commands:
Input `docker run` Command

92 / 65,536 characters. The command is parsed in this tab; shell commands are never executed.

Generated `docker-compose.yml`

Was this Docker Run to Docker Compose Converter helpful?

Help us keep tools reliable, fast, and bug-free.

What you can do with Docker Run to Docker Compose Converter

  • Convert docker run to compose
  • Generate compose file

How this developer utility works

Convert supported docker run options into a safely serialized Compose service. Unsupported flags and unquoted shell operators, redirects, or command substitutions produce an error instead of partial YAML.

Example input

docker run --detach --name web --publish 8080:80 --volume ./site:/usr/share/nginx/html:ro --env NODE_ENV=production --restart unless-stopped nginx:alpine

Example output

services:
  web:
    image: nginx:alpine
    restart: unless-stopped
    container_name: web
    ports:
      - '8080:80'
    volumes:
      - ./site:/usr/share/nginx/html:ro
    environment:
      NODE_ENV: production

Practical workflow

  1. Paste one docker run command with its image and options; the parser accepts quoted values and line continuations but never executes shell text.
  2. Review the Compose service name, image, command, ports, mounts, environment, and runtime options before using it.
  3. Check variable interpolation and compare any unrecognized Docker behavior with the original command before starting the service.
  4. Copy or download the YAML, then use docker compose up -d to start the service detached.

Common use cases

  • Migrate ad-hoc docker run commands from documentation into maintainable compose files.
  • Standardize a container's ports, volumes, and env vars in version control.
  • Combine several converted services into one compose stack.

Important notes and limitations

  • Maps --name, publish and volume flags, environment values, restart, work directory, user, hostname, entrypoint, platform, labels, and interactive TTY flags; unknown options are rejected instead of silently omitted.
  • No image, container name, or restart policy is invented. The --detach flag is handled by docker compose up -d; --rm cannot be represented in a service file and is reported as an error.
  • The parser never executes shell text. It rejects unquoted shell operators, redirects, backticks, and $() substitutions; text inside quotes is preserved as a literal value. Docker Compose can still interpolate ${...} expressions when you use the YAML.
  • The PostgreSQL preset contains REPLACE_WITH_STRONG_PASSWORD as a reminder; use a secret manager or an untracked environment file for real credentials.

Terminal & CLI equivalents

Docker run production container example

docker run -d --name web -p 8080:80 -v ./data:/data:ro --restart unless-stopped nginx:alpine

Runs a background container with port forwarding, read-only volume, and restart policy.

Verify compose.yaml syntax

docker compose config

Validates docker-compose.yml syntax and resolves environment variable references.

Docker Run Flags to Compose v2 Directives

Docker Run CLI OptionCompose v2 DirectiveExample CLI SyntaxExample Compose YAML
-p, --publishports:-p 8080:80ports: - "8080:80"
-v, --volumevolumes:-v /data:/app:rovolumes: - /data:/app:ro
-e, --envenvironment:-e PORT=3000environment: - PORT=3000
--restartrestart:--restart unless-stoppedrestart: unless-stopped
--networknetworks:--network app-netnetworks: - app-net

Common errors & troubleshooting

YAML Exception: mapping values are not allowed here

Cause: Indentation contains tab characters or a colon is missing a trailing space.

Solution: Use 2 spaces for indentation and ensure every key is followed by a space ('key: value').

Continue your workflow

  • cURL to Code Converter — convert cURL healthcheck commands into application code.
  • Cron Parser — schedule automated maintenance jobs and container restarts.
  • SSH Key Generator — generate deploy keys for automated CI/CD container deployments.
  • Diff Checker — compare staging and production docker-compose.yml definitions.

Frequently asked questions

How do I convert a docker run command to a Compose service?

Paste one command with its image and supported flags. The browser parses it and serializes a Compose service with the recognized options; review the YAML before starting containers.

Which docker run flags are converted?

It maps names, published ports, mounts, environment variables, restart policy, work directory, user, hostname, entrypoint, platform, labels, and interactive TTY flags. It reports unsupported flags instead of dropping them.

Does the converter execute shell commands or send the input to a server?

No. Parsing and YAML generation run in the browser; the converter never invokes a shell. It rejects unquoted shell operators, redirects, backticks, and $() substitutions, while preserving quoted text as a literal value. Docker Compose can later interpolate ${...} expressions when you use the generated file.