Don't like ads? Go Ad-Free Today

Stop Writing docker run Commands — Use Docker Compose Instead

Published on

Most docker run commands turn into unmaintainable flag-soup. This guide shows how to convert docker run to docker compose — with a flag reference table, a real conversion example, and a free converter tool.

Stop Writing docker run Commands — Use Docker Compose Instead 1
ADVERTISEMENT · REMOVE?

Every Docker workflow starts the same way: docker run. One flag, two flags — manageable. But by the time you’re running a container with ports, environment variables, volumes, a restart policy, and a custom network, that command is 400 characters of something nobody can remember, version-control, or hand off to a teammate without a Slack thread full of shame.

Docker Compose is the fix. One YAML file replaces the whole command — and you commit it to git.

Why docker run Stops Scaling

Here’s a typical docker run command for a Node.js app:

docker run -d \
  --name my-app \
  -p 3000:3000 \
  -e NODE_ENV=production \
  -e DATABASE_URL=postgres://user:pass@db:5432/mydb \
  -v ./data:/app/data \
  --network app-network \
  --restart always \
  my-app:latest

That works. Once. Then you close the terminal, open a new one three weeks later, and have no idea what flags you used. There’s nothing to git diff. Nothing to share with a new hire. No way to verify that staging matches production.

What Docker Compose Gives You

Docker Compose takes everything stuffed into that docker run command and puts it in a YAML file called docker-compose.yml. That file:

  • Lives in your repo next to your code
  • Runs with a single docker compose up -d
  • Runs identically on every machine and environment
  • Scales to multi-service setups (app + database + cache) without flag gymnastics

How to Convert a docker run Command

That same command above becomes this docker-compose.yml:

version: "3.9"
services:
  my-app:
    image: my-app:latest
    container_name: my-app
    ports:
      - "3000:3000"
    environment:
      NODE_ENV: production
      DATABASE_URL: postgres://user:pass@db:5432/mydb
    volumes:
      - ./data:/app/data
    networks:
      - app-network
    restart: always

networks:
  app-network:

Same behavior. But now it’s readable, committed, and reproducible.

Start it:

docker compose up -d

Stop it:

docker compose down

docker run Flags to docker-compose.yml Keys

A reference for the flags you’ll hit most often:

docker run flagdocker-compose.yml keyExample
-p 8080:80ports:- "8080:80"
-e FOO=barenvironment:FOO: bar
-v ./data:/datavolumes:- ./data:/data
--network mynetnetworks:mynet
--restart alwaysrestart:always
--name mycontainercontainer_name:mycontainer
--memory 512mmem_limit:512m
--cpus 1.5deploy.resources.limits.cpuscpus: "1.5"
-dUse -d flag at runtimedocker compose up -d

Convert Automatically

If you have a long existing docker run command — especially one inherited from a README or a CI script nobody has touched in two years — you don’t need to map every flag manually. Use the Docker Run to Compose Converter: paste the command in, get a valid docker-compose.yml out.

It handles ports, environment variables, volumes, networks, restart policies, and more. Useful for migrating legacy one-liners without introducing typos during the translation.

If you’re configuring resource limits in your Compose file, the Docker Container Resource Calculator helps you pick sensible memory and CPU values based on your workload — before you commit numbers you pulled from thin air.

Lint Your Dockerfile While You’re at It

Once your Compose file is sorted, check the Dockerfile it builds from. Unpinned base images, missing WORKDIR, redundant RUN layers — these are easy to miss and annoying to debug later. The Dockerfile Linter catches them before they become production problems.

Want To enjoy an ad-free experience? Go Ad-Free Today

Install Our Extensions

Add IO tools to your favorite browser for instant access and faster searching

Add to Chrome Extension Add to Edge Extension Add to Firefox Extension Add to Opera Extension

Scoreboard Has Arrived!

Scoreboard is a fun way to keep track of your games, all data is stored in your browser. More features are coming soon!

ADVERTISEMENT · REMOVE?
ADVERTISEMENT · REMOVE?
ADVERTISEMENT · REMOVE?

News Corner w/ Tech Highlights

Get Involved

Help us continue providing valuable free tools

Buy me a coffee
ADVERTISEMENT · REMOVE?