Generate a docker-compose file from the docker run commands you already use
Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.The quickest way to a working docker-compose file is to start from the docker run commands that already work for you. Paste them, several at once if your app has a database and a web server, and each becomes a service with its ports, environment, volumes, restart policy and health check. Named volumes and shared networks are declared for you, so docker compose up -d starts the same setup.
Paste or type your input.
Choose the options you need.
Press Ctrl+Enter, then copy or download.
A docker run command that works is the best starting point for a compose file, but rewriting 10 flags by hand invites mistakes. Paste the command, or several, and get a compose.yaml with one service each, following the Compose Specification, so it works with docker compose up -d.
| docker run | compose.yaml |
|---|---|
--name web |
container_name: web |
-p 8080:80 |
ports: ["8080:80"] |
-e KEY=value |
environment: ["KEY=value"] |
-v data:/data |
volumes: plus a top-level data: |
--network shop-net |
networks: plus shop-net: external: true |
--restart unless-stopped |
restart: unless-stopped |
-it |
stdin_open: true, tty: true |
--gpus all |
deploy.resources.reservations.devices |
What is understood. More than 70 docker run flags, in every spelling the Docker CLI accepts: --flag value, --flag=value, -p80:80 and grouped short flags such as -it or -dp 3000:3000. Commands broken over lines with \ (bash), ^ (cmd) or ` (PowerShell) are joined, quotes are read as a shell reads them, and $(pwd) in a volume becomes ./, because Compose resolves paths from the compose file's folder.
The rest of the article, and all 6 questions about Docker Run to Compose Converter, are on the Docker Run to Compose Converter page.
Give each flag its Compose key under a service: the image as image, -p as ports, -e as environment, -v as volumes, --name as container_name and --restart as restart. Named volumes and custom networks also get a top-level entry. Pasting the command here writes the whole compose.yaml, ready for docker compose up -d.
Nothing in the file: Compose services are meant to stay, so there is no key that deletes the container when it stops. For a one-off task, run docker compose run --rm with the service name, which removes that container afterwards. The note under the result says when --rm was left out.
A docker run with --network shop-net uses a network that already exists. Marking it external tells Compose to join that network rather than create its own, so containers started both ways can still talk. To let Compose create and own the network instead, delete the external: true line.
No. The Compose Specification made the version: key obsolete, and recent versions of docker compose warn when it is present. Files generated here start straight with services:, followed by volumes: and networks: when the commands use named volumes or custom networks.
Rates and rules change; check the source before you rely on a figure.
Still stuck? Ask about Docker Run to Compose Converter and anybody who knows can answer. No account needed.
Same job, other tools: JSON to YAML – Turn JSON into clean, readable YAML for configs · YAML Validator – Check YAML syntax and see the exact line and column of each error.
On the related tools: TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON.