One command, dozens of flags, eight that matter
docker run creates a container from an image and starts it. The vast majority of daily use comes down to a small set of flags.
The eight you'll use every day
-d— detached (background). Without it, the CLI attaches to the container's stdout.--name foo— assign a human name. Without it, Docker generates one likeamused_curie.--rm— remove the container when it exits. Perfect for one-off tasks.-it— interactive + TTY. For shells and REPLs.-p 8080:80— map host:container port.-v name:/pathor-v $(pwd):/path— volume / bind mount.-e KEY=VALUEor--env-file .env— environment variables.--restart unless-stopped— restart policy. The right default for long-running services.
Three modes you should remember
Foreground: docker run image — runs and attaches. Ctrl-C stops it.
One-off: docker run --rm -it image bash — interactive shell that auto-cleans.
Service: docker run -d --name app --restart unless-stopped -p 8080:80 image — long-running, named, port-mapped, auto-restart.