Skip to tool

Docker Run to Docker Compose

Docker Run to Docker Compose tool on AzWebTools.

Result

Fill inputs and click run.

How to Use This Tool

  1. Paste your full docker run command into the main input area.
  2. (Optional) Enter a custom service name to override the default naming convention.
  3. Choose your desired Docker Compose YAML version from the dropdown menu.
  4. Click the convert button to generate the YAML configuration.
  5. Copy the resulting output to use in your docker-compose.yml file.

Learn More About Docker Run to Docker Compose

Why Move from Docker Run to Docker Compose?

While docker run is excellent for quickly spinning up a single container, it becomes unwieldy when managing complex applications. As you add environment variables, volume mounts, custom networks, and port mappings, the CLI command turns into a massive, difficult-to-read string.

Docker Compose solves this by using a declarative YAML file to define services. This approach offers several benefits:

  • Version Control: YAML files can be easily tracked in Git, allowing you to monitor configuration changes over time.
  • Reproducibility: A single docker-compose up command replaces complex shell scripts, ensuring every developer runs the exact same environment.
  • Multi-Container Management: Compose allows you to define interconnected services (like a web application and a database) in one file, automatically handling the networking between them.

Common Flag Translations

Here is how common CLI flags map to the Compose YAML schema:

  • -p or --publish translates to the ports: array.
  • -v or --volume translates to the volumes: array.
  • -e or --env translates to the environment: dictionary or array.
  • --name sets the default service name and explicitly assigns the container_name: property.
  • --network translates to custom network bindings under the networks: or network_mode: keys.
  • -d or --detach is implicit in Compose when running docker-compose up -d, so it is typically omitted from the YAML itself.

The Origin of Docker Compose

Docker Compose originated as an open-source tool called Fig, created by Orchard in 2013 to easily manage multi-container Docker applications. Docker acquired Orchard in 2014 and rebranded Fig as Docker Compose, making it the official standard for defining and running complex, interconnected multi-container applications. It revolutionized local development by allowing developers to define their entire stack in a single, declarative YAML file.
Originally known as Fig before its acquisition by Docker, Compose became the industry-standard way to define declarative multi-container environments using YAML.
Original Name
Fig
Acquisition Year
2014
Primary Format
YAML

Examples

Basic Web Server

Runtime-verified example for docker-run-to-docker-compose
Input
{"command":"docker run -d -p 8080:80 --name my-nginx nginx:latest","serviceName":"web-server","composeVersion":"3.8"}
Output
{
  "command": "docker run -d -p 8080:80 --name my-nginx nginx:latest",
  "serviceName": "web-server",
  "composeVersion": "3.8"
}

Database with Volumes & Env

Runtime-verified example for docker-run-to-docker-compose
Input
{"command":"docker run -d --name postgres-db -e POSTGRES_PASSWORD=secret -v /my/data:/var/lib/postgresql/data -p 5432:5432 postgres:13","serviceName":"db","composeVersion":"3.8"}
Output
{
  "command": "docker run -d --name postgres-db -e POSTGRES_PASSWORD=secret -v /my/data:/var/lib/postgresql/data -p 5432:5432 postgres:13",
  "serviceName": "db",
  "composeVersion": "3.8"
}

Use Cases

  • Migrating legacy shell scripts that run standalone containers into manageable Docker Compose files.
  • Sharing easily reproducible container development environments with team members.
  • Simplifying complex container deployment documentation into readable YAML formats.
  • Learning Docker Compose syntax by directly comparing it to familiar CLI commands.

Frequently Asked Questions