Anúncios incomodam? Ir Sem anúncios Hoje

Parar de escrever comandos docker run — Use Docker Compose em vez disso

Publicado em

A maioria dos comandos docker run se torna uma confusão de flags difícil de manter. Este guia mostra como converter o comando docker run para docker compose — com uma tabela de referência de flags, um exemplo real de conversão e uma ferramenta gratuita de conversão.

Stop Writing docker run Commands — Use Docker Compose Instead 1
ANUNCIADO Remover?

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 keyExemplo
-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 o -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 Conversor de Docker Run para Compose: 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 Calculadora de Recursos de Contêineres Docker 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.

Quer eliminar anúncios? Fique sem anúncios hoje mesmo

Instale nossas extensões

Adicione ferramentas de IO ao seu navegador favorito para acesso instantâneo e pesquisa mais rápida

Ao Extensão do Chrome Ao Extensão de Borda Ao Extensão Firefox Ao Extensão Opera

O placar chegou!

Placar é uma forma divertida de acompanhar seus jogos, todos os dados são armazenados em seu navegador. Mais recursos serão lançados em breve!

ANUNCIADO Remover?
ANUNCIADO Remover?
ANUNCIADO Remover?

Notícias com destaques técnicos

Envolver-se

Ajude-nos a continuar fornecendo ferramentas gratuitas valiosas

Compre-me um café
ANUNCIADO Remover?