Parar de escrever comandos docker run — Use Docker Compose em vez disso
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.
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 flag | docker-compose.yml key | Exemplo |
|---|---|---|
-p 8080:80 | ports: | - "8080:80" |
-e FOO=bar | environment: | FOO: bar |
-v ./data:/data | volumes: | - ./data:/data |
--network mynet | networks: | mynet |
--restart always | restart: | always |
--name mycontainer | container_name: | mycontainer |
--memory 512m | mem_limit: | 512m |
--cpus 1.5 | deploy.resources.limits.cpus | cpus: "1.5" |
-d | Use o -d flag at runtime | docker 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.
Você também pode gostar
Instale nossas extensões
Adicione ferramentas de IO ao seu navegador favorito para acesso instantâneo e pesquisa mais rápida
恵 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!
Ferramentas essenciais
Ver tudo Novas chegadas
Ver tudoAtualizar: Nosso ferramenta mais recente foi adicionado em 22 abr 2026
