Why Convert Between Docker Run and Docker Compose?
Containerized development requires flexibility between ad-hoc terminal debugging and reproducible infrastructure-as-code. Developers frequently encounter two opposite challenges:
- Migrating GitHub README commands to Compose: Open-source projects (like Nextcloud, PostgreSQL, or Nginx) typically document installation with long
docker run -d -p 8080:80 -v ...commands. Pasting them directly into a terminal makes version control, secrets management, and automated restarts difficult. Converting them intodocker-compose.ymlallows versioned, single-command deployment withdocker compose up -d. - Quick CLI Testing from Compose: When debugging a failing container in a multi-service Compose stack, spinning up the entire stack with
docker compose upcan be slow. Extracting an equivalentdocker runcommand lets engineers test flags, override entrypoints, and attach interactive shells (-it) in seconds.
Docker Run Flags vs. Docker Compose Directives
The table below outlines how common Docker CLI flags map to modern Docker Compose Specification keys:
| Docker Run Flag | Compose YAML Directive | Purpose |
|---|---|---|
| -p 8080:80 | ports: - "8080:80" | Binds host port 8080 to container port 80 |
| -v ./data:/app:ro | volumes: - ./data:/app:ro | Binds host directory with read-only permission |
| -e DB_PASS=secret | environment: - DB_PASS=secret | Passes environment variables to container processes |
| --restart unless-stopped | restart: unless-stopped | Defines container crash and system reboot recovery |
| --health-cmd "curl -f ..." | healthcheck: test: [...] | Monitors application health status for service readiness |
| --memory 1g --cpus 2 | deploy: resources: limits: ... | Prevents container out-of-memory crashes on shared hosts |
Handling Named Volumes vs. Host Bind Mounts
Docker distinguishes between host bind mounts (which point to specific directories on the host operating system) and Docker-managed named volumes (stored under /var/lib/docker/volumes/):
- Bind Mounts: Any path starting with
./,../,/, or~is treated as a bind mount and stays under the service'svolumes:list. - Named Volumes: Any volume without leading path separators (e.g.
pgdata:/var/lib/postgresql/data) is detected as a named volume. This tool automatically declares it in the root-levelvolumes:section of the generateddocker-compose.ymlfile.
Security & Privacy: 100% In-Browser Execution
When dealing with infrastructure commands, developers frequently paste sensitive credentials such as database passwords, Stripe webhooks, or AWS credentials in -e flags. Unlike legacy online converters that send your commands to external backend servers, this tool parses every token using in-browser JavaScript. Your infrastructure commands and secrets never leave your device.