Docker Run → Compose Converter

Convert a docker run command to a docker-compose.yml service definition. Supports ports, volumes, environment variables, networks, and more.

services:
  nginx:
    image: nginx:alpine
    container_name: nginx
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/www:/usr/share/nginx/html:ro
      - /etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro

About the Docker Run to Compose Converter

The docker run command is a powerful one-liner for starting containers with a full set of options — but as services grow more complex, managing them with raw docker run commands becomes unwieldy. Docker Compose solves this by declaring all service configurations in a docker-compose.yml file that can be committed to source control, reviewed, and run with a single docker compose up -d. This tool converts any docker run command into the equivalent Compose service definition automatically.

The converter handles the most common flags: -p (ports), -v (volumes), -e / --env-file (environment), --restart, --network, --name, --hostname, --user, --workdir, --privileged, --cap-add, --cap-drop, --device, --memory, --cpus, --link, and --entrypoint. Flags that Compose handles differently (-d, --rm, -it) are intentionally omitted.

All conversion runs locally in your browser. No Docker commands or secrets are sent to any server. After converting, review the generated YAML carefully — some flags may require additional configuration (like named volume declarations or custom network definitions) that Compose requires at the top-level.

Frequently Asked Questions

What is Docker Compose?

Docker Compose is a tool for defining and running multi-container Docker applications. You describe services, networks, and volumes in a docker-compose.yml file, then use docker compose up to start everything. It replaces long docker run commands with readable, version-controlled configuration.

What is the difference between docker-compose and docker compose?

docker-compose is the original standalone tool (v1, written in Python). docker compose (no hyphen) is the newer plugin integrated into the Docker CLI (v2, written in Go). Docker v2 is the current standard and ships with Docker Desktop. Both use the same YAML format.

What happens to --rm and -d flags?

The --rm flag (remove container on exit) has no direct Compose equivalent — Compose services are expected to be persistent. The -d (detached) flag is the default behavior when running docker compose up -d. These flags are intentionally dropped during conversion.

How do I add multiple services to my compose file?

Convert each docker run command separately and combine the results under a single services: key. If services share a network or volumes, declare them in the top-level networks: and volumes: sections. Services can reference each other by name as hostnames within the same Compose network.

Why should I use Compose instead of docker run?

Compose files are declarative, versionable, and reproducible. They make it easy to spin up entire stacks (docker compose up), tear them down (docker compose down), view logs (docker compose logs), and share configurations with teammates. A docker run command in your shell history is fragile; a Compose file in your repository is permanent.