Docker Run Command Generator
Build a docker run command visually from ports, volumes, env vars and flags — then convert it to an equivalent docker-compose.yml. Runs entirely in your browser.
docker run \ -d \ --name web \ -p 8080:80 \ -v ./html:/usr/share/nginx/html:ro \ -e TZ=UTC \ --restart unless-stopped \ nginx:latest
services:
web:
image: nginx:latest
container_name: web
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html:ro
environment:
TZ: UTC
restart: unless-stoppedBuild a docker run command
Fill in the image and any flags you need above, and the docker run command updates live. The generator handles the most common flags — detached mode, container name, published ports, bind and named volumes, environment variables, restart policy and an optional network — and escapes each onto its own line so the command stays readable.
Common flags (ports, volumes, env, restart)
-p host:container publishes a port, -v source:target mounts a volume, -e KEY=value sets an environment variable, and --restart unless-stopped keeps the container alive across reboots. Add one entry per line for ports, volumes and env vars and each becomes its own flag.
Convert docker run ↔ docker-compose
The right-hand panel mirrors your command as a docker-compose.yml. Each flag maps to a compose key: ports, volumes, environment, restart and container_name. Paste it into a file and run docker compose up -d. For a deeper walkthrough see our guide on docker-compose for development environments.
Docker run best practices
Pin image tags instead of latest, mount configuration read-only with :ro, avoid baking secrets into the image, and prefer named volumes for data you want to survive a container rebuild. When your image itself needs slimming, a multi-stage build keeps the final image small and secure.
FAQ
How do I convert a docker run command to docker-compose?
Map each docker run flag to its compose key: -p becomes ports, -v becomes volumes, -e becomes environment, --restart becomes restart, --name becomes the service name and the image becomes image. This tool does that mapping for you and prints ready-to-paste YAML.
What is the difference between docker run and docker-compose?
docker run starts a single container from the command line, while docker-compose defines one or more services declaratively in a docker-compose.yml file so you can start the whole stack with docker compose up. Compose is preferred for anything beyond a single throwaway container.
Does this tool upload my configuration?
No. Everything runs client-side in your browser. Your image names, environment variables and ports never leave your machine, which matters because docker run env vars often contain secrets.
Which restart policy should I use?
Use unless-stopped for long-running services you want back after a reboot but not after a manual stop, always for critical daemons, and on-failure for batch jobs that should retry only on a non-zero exit.