Docker Run to Compose Converter

Paste a docker run command and get the equivalent docker-compose.yml service definition, with the image, container name, port mappings, volumes, environment variables, and restart policy detected automatically.

FreeOnline Tool
Loading…

How to Use

  1. Paste a complete docker run command into the input box, for example: docker run -d --name myapp -p 8080:80 -v /data:/app/data -e NODE_ENV=production node:18
  2. Click the "Convert" button and the matching docker-compose.yml content appears below.
  3. If the command contains arguments the tool cannot fully interpret, a note explaining this is shown above the result.
  4. Click "Load sample data" to see a full example that includes ports, volumes, and environment variables.

Features

  • Parses the common parts of a docker run command: image name, container name (--name), port mappings (-p), volume mounts (-v), and environment variables (-e).
  • Recognizes further arguments such as the restart policy and network mode and maps them to the corresponding Compose fields.
  • Produces a standard docker-compose.yml service definition you can copy and use directly.
  • Flags arguments that could not be handled so nothing important slips through the conversion unnoticed.
  • Shows a clear error when the command is empty or cannot be parsed.

Use Cases

Moving a single container to Compose
Take a long docker run command you already rely on and turn it into a docker-compose.yml file you can version and share with the team.
Tidying up deployment docs
Convert the scattered docker run commands in your scripts or README into a consistent Compose file that is easier to read and maintain.
Learning Compose syntax
Compare docker run flags you already know with the Compose YAML they map to and pick up the file format quickly.
Building a local multi-service environment
Convert several docker run commands one by one and merge the results into a single Compose file for local development.

FAQ

Which docker run arguments are supported?
Built on an open-source conversion library, it handles the image name, --name, -p port mappings, -v volume mounts, -e environment variables, --restart, and other common flags. Unusual or complex arguments may not be fully covered, and the result notes when that happens.
What if the output looks incomplete?
Notes above the result explain which arguments may not have been fully processed. Always review the generated YAML by hand, especially for long or non-standard docker run commands.
What happens with an empty or malformed command?
An empty input reports that the command is empty. If the command cannot be parsed, the specific error is shown and no invalid YAML is produced.
Does the command get uploaded anywhere?
No. Conversion happens entirely in your browser and the command is never sent to a server, so it is safe to paste commands containing internal environment variables.