Docker Run to Docker Compose Converter
Paste a docker run command and get a docker-compose.yml service you can edit, copy or download. Everything happens in your browser; nothing is uploaded.
Updated November 19, 2026
docker run command
docker-compose.yml
Notes
- -d (detached) has no Compose key: start the stack with "docker compose up -d".
- Custom networks are declared as "external: true", meaning they must already exist (docker network create <name>). Remove that line to let Compose create them.
How to convert docker run to docker compose
- Paste your command. Multi-line commands ending in
\, quoted values and a leading$orsudoare handled. - Check the YAML, the unsupported flags and any secret warnings, and edit the YAML if needed.
- Copy it or download
docker-compose.yml, then rundocker compose up -din the same folder.
Worked example
docker run -d --name web -p 8080:80 -e TZ=UTC --restart unless-stopped nginx:1.27 becomes a web service with image: nginx:1.27, container_name: web, ports: - "8080:80", environment: - TZ=UTC and restart: unless-stopped. The -d flag is not part of the file; it is the -d in docker compose up -d.
Compose files are YAML: check or convert one with the YAML to JSON converter. Volume paths on Linux hosts may need the chmod calculator. More converters: JSON to TypeScript, CSV to JSON and diff checker. Always verify the result with docker compose config.
Frequently Asked Questions (FAQ)
Paste the whole docker run command, including multi-line commands that end in a backslash. The tool turns each flag into the matching Compose key (ports, volumes, environment, restart and so on) and shows a docker-compose.yml you can edit, copy or download. Then run docker compose up -d.
No. The conversion runs entirely in your browser and nothing is sent to a server. Even so, avoid pasting real passwords or tokens into any website; use placeholders and an env file.
Flags with no Compose equivalent, such as -P, --rm, --ip and --network-alias, are listed under Unsupported flags with the reason, never dropped silently. -d is explained as docker compose up -d. Unknown flags are assumed to take no value; write them as --flag=value if they do.
Environment values that look like passwords, tokens or keys would end up in a plain-text YAML file that is easy to commit by mistake. Move them to an env_file kept out of version control, or reference a variable such as ${DB_PASSWORD} that Compose reads from a .env file.
A named volume (-v data:/data) is added to the top-level volumes section. A custom network (--network mynet) is added as an external network, which must already exist; remove external: true to have Compose create it. host, none and bridge become network_mode.
In Compose files a single $ starts variable interpolation. A $ that was literal in your shell command (inside single quotes) is written as $$ so it stays literal. Shell variables such as $HOME are left as written and Compose reads them from your environment.
Yes. Put each command on its own line (or separate lines with no trailing backslash) and each becomes a service in the same file, with unique service names.
No. It covers the common docker run options. Check the result against the Compose file reference, especially for networking, resource limits and GPUs, and validate it with docker compose config.
Related Tools
- cURL to fetch, Axios and Python requests ConverterPaste a cURL command and get JavaScript fetch, Axios or Python requests code. Parsed in your browser; nothing is uploaded.
- Cron Expression Generator and ExplainerBuild cron expressions from dropdowns, explain them in plain English and preview the next 5 run times in your timezone.
- JSON ValidatorValidate, format and visualize your JSON data with ease.
- CSV to JSON ConverterConvert CSV data to JSON format with customizable options.
- Unix Timestamp ConverterConvert epoch seconds or milliseconds to dates in UTC and local time, and dates back to timestamps. Live clock and code snippets.
- UUID Generator (v4 & v7)Generate random v4 or time-ordered v7 UUIDs in bulk with your browser’s secure random source. Copy or download.