- Paste your full
docker runcommand into the main input area. - (Optional) Enter a custom service name to override the default naming convention.
- Choose your desired Docker Compose YAML version from the dropdown menu.
- Click the convert button to generate the YAML configuration.
- Copy the resulting output to use in your
docker-compose.ymlfile.
Docker Run to Docker Compose
Docker Run to Docker Compose tool on AzWebTools.
Result
Fill inputs and click run.
How to Use This Tool
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 upcommand 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:
-por--publishtranslates to theports:array.-vor--volumetranslates to thevolumes:array.-eor--envtranslates to theenvironment:dictionary or array.--namesets the default service name and explicitly assigns thecontainer_name:property.--networktranslates to custom network bindings under thenetworks:ornetwork_mode:keys.-dor--detachis implicit in Compose when runningdocker-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.