Docker
docker run to Compose
Convert a working docker run command into a Compose service definition, with the traps flagged.
docker run command
Line continuations are fine. Quoted values keep their spaces.
Examples
compose.yaml
postgres:16-alpine
services:
db:
image: "postgres:16-alpine"
container_name: db
ports:
- "5432:5432"
volumes:
- "pgdata:/var/lib/postgresql/data"
environment:
POSTGRES_PASSWORD: secret
POSTGRES_DB: app
restart: unless-stopped
volumes:
pgdata:
- Info
Port mappings are quoted. Unquoted, YAML 1.1 reads "8080:80" as a sexagesimal number — a long-standing Compose trap.
- Medium
A credential appears to be passed inline. Move it to an env_file that is git-ignored, or to a secrets mechanism — `docker inspect` exposes inline environment to anyone with daemon access.
- Info
-d is not carried over: `docker compose up -d` controls that at the command line.