Docker Command Builder

Build docker run commands and compose.yaml, or convert docker run to Compose
Fill in a form and get the docker run command and the matching compose.yaml, or paste a docker run command to have every flag explained and turned into Compose. It warns about the mistakes that hurt later: database ports open to the internet (Docker skips ufw), docker.sock and --privileged, :latest tags, passwords on the command line, and logs that fill the disk.
RUNS ENTIRELY IN YOUR BROWSER · NOTHING IS SENT ANYWHERE
Start from:
Ports
Volumes and folders
Environment variables
More options

Everyday commands

docker psRunning containers. Add -a to see stopped ones too.
docker logs -f --tail 100 NAMEFollow a container’s output, starting with the last 100 lines.
docker exec -it NAME shOpen a shell inside a running container (bash if the image has it).
docker compose up -dStart everything in compose.yaml in the background, or apply changes to it.
docker compose pull && docker compose up -dUpdate: pull newer images, then recreate only the containers that changed.
docker compose logs -fFollow the logs of every service in the file.
docker compose downStop and remove the containers and network. Named volumes stay.
docker statsLive CPU, memory and network use per container.
docker system dfDisk space used by images, containers, volumes and build cache.
docker image pruneDelete dangling images. -a deletes every image no container uses.

Docker mistakes worth knowing

docker run and Compose, side by side

Fill in the image, ports, volumes and variables, or start from a recipe such as PostgreSQL or Nginx, and get both the docker run command and a compose.yaml that does the same thing. Paste an existing docker run command to have each flag explained in plain words and turned into Compose. The Compose files it writes were tested with Docker Compose’s own checker, docker compose config.

Common questions

How do I convert a docker run command to Docker Compose?

Each flag has a Compose key: -p becomes ports, -v becomes volumes, -e becomes environment, --restart becomes restart and --name becomes container_name. Named volumes are also listed at the bottom of the file. Paste the command above to do it automatically, then run docker compose up -d.

Why does Docker ignore my ufw firewall?

Docker writes its own iptables rules for published ports, and they take effect before ufw’s rules. So -p 5432:5432 is open to the internet even when ufw denies port 5432. Publish on 127.0.0.1:5432:5432 when only the server needs it, or don’t publish at all: containers on the same network reach each other by name.

What is the difference between restart always and unless-stopped?

Both restart a container after a crash or a reboot. The difference is a container you stopped yourself: with unless-stopped it stays stopped, while with always it starts again the next time the Docker service starts. unless-stopped is the usual choice.

How do I stop Docker logs from filling the disk?

The default json-file log driver never rotates. Add --log-opt max-size=10m --log-opt max-file=3 to a container, or set "log-opts": {"max-size": "10m", "max-file": "3"} in /etc/docker/daemon.json and restart Docker. The daemon setting applies to containers created after the change.

How do I keep passwords out of docker run and compose.yaml?

Put them in an env file that only you can read (chmod 600) and use --env-file or env_file:. Better still, many official images accept a _FILE variable, such as POSTGRES_PASSWORD_FILE, which reads the password from a Compose secret mounted at /run/secrets/.

Related tools: Compose Visualizer · K8s Manifest Builder · All tools A–Z