About docker run command generator
docker run starts a container. The builder helps assemble ports, environment variables, volumes and restart policy without remembering every flag.
Key flags
- -p host:container publishes a port.
- -e sets an environment variable and -v mounts a volume.
- -d runs in the background, --rm removes the container when it stops.
- --restart unless-stopped restarts it after a reboot.
A worked example
docker run -d --name web -p 8080:80 -v $(pwd)/site:/usr/share/nginx/html:ro --restart unless-stopped nginx runs Nginx in the background, publishes port 8080, serves a local folder read-only and restarts after reboots. Open http://localhost:8080 to test.
Housekeeping
- docker ps shows running containers and docker logs -f web follows output.
- docker stop and docker rm remove a container.
- docker system prune frees disk space, so read its warning first.
Environment variables
Add settings with -e NAME=value, or use --env-file .env to load many. Never bake secrets into the image. Pass them at run time.
