Skip to main content
ToolsHub

docker run to docker-compose

Paste a docker run command and get a ready-to-use docker-compose.yml service with ports, env, volumes and restart mapped — all in your browser.

Updated

Files never leave your browser

How to use docker run to docker-compose

The docker run to docker-compose converter turns a long, flag-heavy docker run command into a clean docker-compose.yml service, instantly in your browser. Paste the command you normally type in the terminal and the tool parses its ports, environment variables, volumes, restart policy, network, working directory and more, then emits the equivalent Compose service block. Moving a container from an ad-hoc CLI invocation to a versioned Compose file makes it reproducible, reviewable and easy to extend — and because the parsing happens locally, your commands and any secrets they contain never leave the page.

  1. Copy the full docker run command, including all its flags.
  2. Paste it into the input area.
  3. The equivalent docker-compose.yml service is generated automatically.
  4. Review the mapped ports, environment, volumes and other keys.
  5. Copy the YAML into your docker-compose.yml and run docker compose up.

Your data never leaves your device — 100% private processing.

How flags map to Compose keys

Each docker run flag has a direct counterpart in the Compose service schema, and the converter applies the standard mapping. Published ports from -p or --publish become entries under ports, environment variables from -e or --env become environment entries, and bind mounts or named volumes from -v or --volume become volumes. The --name flag sets both the service name and container_name, --restart sets the restart policy, --network adds the service to a network, and -w/--workdir, --entrypoint, -u/--user, --hostname and -l/--label map to working_dir, entrypoint, user, hostname and labels respectively. Any arguments that appear after the image name are collected into the command field so the container starts exactly as it did from the CLI.

docker run flag to Compose key mapping
docker run flagCompose key
-p / --publishports
-e / --envenvironment
-v / --volumevolumes
--namecontainer_name
--restartrestart
--networknetworks
args after imagecommand

Single service vs a full stack

A docker run command starts exactly one container, so the converter emits exactly one service under the services key. Real applications often need several containers — for example a web app plus a database and a cache — and Compose is designed for precisely that. To build a multi-service stack, run each docker run command through the tool and combine the resulting service blocks into a single docker-compose.yml, indenting each under the shared services key. You can then add cross-cutting configuration such as a shared network, depends_on ordering, or named volumes that several services reference. The output deliberately omits the top-level version field because Compose v2 treats it as obsolete and will warn if it is present.

Worked examples

Basic web server

Inputs: docker run -d -p 8080:80 nginx

Result: A service “nginx” with image nginx and ports 8080:80.

With env and volume

Inputs: docker run --name db -e POSTGRES_PASSWORD=x -v data:/var/lib/postgresql/data postgres

Result: A service “db” with environment and volumes mapped.

Glossary

docker run
The Docker CLI command that creates and starts a single container from an image with a set of flags.
docker-compose.yml
A YAML file describing one or more services so a whole application can be started with a single command.
Service
A named container definition inside a Compose file, including its image and runtime configuration.
Bind mount
A volume mapping that connects a host path to a path inside the container, written as host:container.
Restart policy
A rule such as unless-stopped that tells Docker when to automatically restart a container.

Related reading

Frequently Asked Questions

Free · No spam

Get weekly tool tips & updates

New tools, power-user tips, and productivity hacks — delivered free every Friday.

No spam, ever. Unsubscribe with one click.

Why use docker run to docker-compose?

  • Convert a docker run command to a Compose service in one paste
  • Maps ports, env vars, volumes, restart, network, workdir and labels
  • Produces modern Compose v2 output with no obsolete version key
  • Derives a sensible service name from --name or the image
  • Runs entirely client-side, so commands and secrets stay local

Common use cases

  • Migrate a container from a shell script to a versioned compose file
  • Document how a container is run in a reviewable YAML format
  • Bootstrap a multi-service stack one container at a time
  • Share a reproducible setup with teammates instead of a CLI snippet
  • Convert README “docker run” instructions into a compose example

Related Developer Tools

Explore all Developer Tools.