Docker run to Compose
Convert supported static docker run arguments into Compose YAML without executing any commands.
How it works & useful details
How it works & supported syntax
Converts static POSIX-like docker run arguments: name, publish, env NAME=value, volume, restart, entrypoint, user, workdir, hostname, interactive, tty, read-only and privileged. -d is noted as a launch choice. Unknown flags, inherited environment values, shell operators, expansions and unquoted globs are rejected.
Volumes support absolute Linux source paths or named volumes with /container/path and optional ro/rw. Ports support single numeric ports, optional IPv4 host binding and protocol. No ranges, IPv6 bindings, mount-option DSL or Windows paths. Literal dollar signs are escaped for Compose interpolation. Commands are preserved as argument lists; nothing is executed or checked against Docker.
Local workspace
Your input stays in this page. These tools calculate or process text; they do not run commands, start containers, contact servers or change settings on your device.
Previews pause above 20,000 combined characters. Use the action to process the full supported input. Exports contain the complete result within the tool’s stated limits.
About this tool
Docker run to Compose converts supported static docker run arguments into a Compose service definition. It is a quick way to capture a command you already run into a reproducible file for a project.
The conversion handles static flags it understands and reports anything it cannot represent, such as shell substitution or flags specific to newer Docker versions. No command is executed and no image is pulled.
How to use it
- Paste the docker run command.
- Review the parsed image, ports, volumes, environment, and options.
- Generate the Compose YAML and read the warnings.
- Copy the service definition into your compose file.
Worked example
docker run -d --name web -p 8080:80 -e APP_ENV=production --restart unless-stopped nginx:alpinebecomes
services:
web:
container_name: web
restart: unless-stopped
image: "nginx:alpine"
ports:
- "8080:80"
environment:
APP_ENV: production-d (detached) has no Compose equivalent, because it is chosen when you start the stack: docker compose up -d. The tool notes this instead of dropping the flag silently.
Why move from docker run to Compose
A long docker run command is hard to read, easy to mistype, and lives only in shell history or a README. A Compose file is versioned with the project, starts several containers together, and documents ports, volumes, and environment in one place. Converting is the usual first step when a single container grows into a small stack.
Supported flags include --name, -p, -e NAME=value, -v, --restart, --entrypoint, --user, --workdir, --hostname, -i, -t, --read-only, and --privileged. Unknown flags, -e NAME without a value (which inherits from your shell), variables, and shell operators are rejected. A partial conversion could otherwise behave differently from the original command. Dollar signs are doubled ($$), so Compose does not treat them as variables.
Frequently asked questions
Which flags are supported?
Common static flags such as ports, volumes, environment variables, names, and restart policies. Unsupported flags are listed explicitly.
Are shell variables resolved?
No. Values are kept as written, and dynamic substitutions should be moved to Compose interpolation or an .env file.
What is the limit?
Commands are limited to about 20,000 characters.
Can it convert --network or --gpus?
Not yet. They are rejected as unsupported flags. Add networks and device reservations to the Compose file by hand.
