Pages

Topics

Tools

↑↓navigate↵openescclose
Encoding & Security

Docker Run ↔ Compose

Convert a docker run command into a compose.yaml service and back, with ports, environment, volumes, mounts, networks, restart policy and command intact, and a note for every flag Compose cannot express.

Runs entirely in your browser — nothing you paste is uploaded.

Presets
231 chars
1 service3 variables1 port1 volume

Forward and back conversions run in this browser tab; nothing you paste is uploaded.

live
compose.yaml
323 chars · 15 lines
services:
  blog-db:
    image: postgres:16-alpine
    container_name: blog-db
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: blog
      POSTGRES_PASSWORD: change-me
      POSTGRES_DB: blog
    volumes:
      - blog-db-data:/var/lib/postgresql/data
    restart: unless-stopped
volumes:
  blog-db-data:

Save this as compose.yaml and run it with docker compose up -d.

docker run to Compose cheat sheet

quick reference
docker run -d --name web -p 3000:3000 image
The image is the first argument that is not a flag; everything after it is the command Compose writes under command:.
-p 8080:80
Compose splits the same value into host:container under ports:, and a leading host IP such as 127.0.0.1:8080:80 is kept as written.
-e KEY=VALUE
Repeated -e flags become an environment map. A bare -e KEY with no value turns the whole block into the list form Compose interpolates from the host.
-v name:/path
A named volume also needs the top-level volumes: entry that Compose writes for you; a path starting with / or . is a bind mount instead.
--restart unless-stopped
Restart policies carry over unchanged, and Compose itself stops a service with restart: "no" rather than the docker run --rm flag.
docker compose up -d
What replaces the docker run command: Compose runs the service detached, so the -d flag has no equivalent in the file.

Frequently asked questions

answered below the tool
Why is one of my flags in a note?

A few flags, such as --rm or --pull, have no compose.yaml equivalent, so they are listed instead of being dropped silently.

How do volumes become Compose entries?

A named volume also writes the top-level volumes: block, while a path starting with / or . becomes a bind mount.

Can I go from compose.yaml back to docker run?

Yes. Each service becomes one docker run command with its ports, environment, volumes, network and restart policy.

All Docker guides