Docker run to Docker compose converter

What is a Docker Run To Docker Compose Converter?

A long docker run command with ports, volumes and environment variables is hard to read, easy to mistype and impossible to version properly. Docker Compose describes the same container in a YAML file you can commit, review and start with one command. This converter turns your existing docker run commands into a Compose service definition.

How to use it

  1. Paste one or more docker run commands.
  2. Copy the generated docker-compose.yml.
  3. Run docker compose up -d in the same folder.

Example

Input:

docker run -d --name db -p 5432:5432 -e POSTGRES_PASSWORD=secret -v pgdata:/var/lib/postgresql/data --restart unless-stopped postgres:16

Output:

services:
  db:
    image: postgres:16
    container_name: db
    ports:
      - 5432:5432
    environment:
      - POSTGRES_PASSWORD=secret
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: unless-stopped
volumes:
  pgdata:

Flag mapping

  • -p becomes ports, -v becomes volumes, -e becomes environment.
  • --name becomes container_name, --restart becomes restart.
  • --network becomes networks; -d is implied by docker compose up -d.

After converting

  • Move secrets out of the file into an .env file or Docker secrets.
  • Remove container_name if you want to scale a service.
  • Add depends_on with health checks when one service needs another.
  • Put services that talk to each other in the same Compose file; they can reach each other by service name.

Frequently Asked Questions

Why use Docker Compose instead of docker run?

Compose files are readable, version-controlled and can start several related containers with one command.

Is the version key still needed in docker-compose.yml?

No. Modern Docker Compose ignores the top-level version key, so it can be omitted.

How do I keep passwords out of the compose file?

Use an .env file with variable substitution, or Docker secrets, and keep the .env file out of version control.

Can I convert several docker run commands at once?

Yes. Each command becomes a service in the same compose file.