Docker Run to Compose Converter
Convert a docker run command into a Docker Compose service.
Overview
Paste a long docker run command and the tool emits the equivalent Docker Compose service block. Ports, volumes, env vars, networks, restart policy, and resource limits all map across, so a one-off command can become a reproducible docker-compose.yml entry in seconds.
It's for developers who've grown tired of pasting the same 200-character docker run into every README, and for ops teams migrating ad-hoc container setups to a Compose-managed stack. Reach for it when stabilising a dev environment, sharing a service definition with a teammate, or laying the groundwork for a future move to Kubernetes manifests.
How it works
The tool tokenises the input against docker run's flag grammar (the same flags documented in the Docker CLI reference) and maps each one to its Compose v3.x key: -p becomes ports:, -v becomes volumes:, -e becomes environment:, --network becomes networks:, --restart becomes restart:. Image name, command, and entrypoint move into image:, command:, and entrypoint:.
Compose output uses the modern compose-spec shape (top-level services:, no version key required), which is what docker compose v2 reads natively. Multi-value flags like repeated -e collapse into a single mapping or list.
Examples
- Simple port + volume:
docker run -d -p 8080:80 -v /data:/srv nginx:latestservices: nginx: image: nginx:latest ports: - "8080:80" volumes: - /data:/srv - Env vars and restart policy:
docker run -e DB_HOST=db -e DB_PORT=5432 --restart unless-stopped myappservices: myapp: image: myapp environment: DB_HOST: db DB_PORT: "5432" restart: unless-stopped - Named network:
docker run --network backend redis:7services: redis: image: redis:7 networks: - backend networks: backend: - With a custom command:
docker run python:3.12 python -c "print('hi')"command: ["python", "-c", "print('hi')"]
FAQ
Does the output need a version: line?
Not for docker compose v2 (which is what ships with modern Docker Desktop). The legacy docker-compose v1 binary expected one, but it's effectively unsupported now.
What about --link?
Container links are deprecated. The converter translates them to a depends_on: entry and recommends putting both services on the same user-defined network instead.
Will environment values be quoted?
Numeric and boolean-looking strings ("5432", "true") are quoted to prevent YAML's type coercion from breaking them. Plain string values are left bare.
How are multi-line commands handled?
The parser accepts backslash-continued multi-line input. Use single-line docker run if you hit edge cases with embedded quoting.