docker run creates and starts a container from an image. With docker run nginx, Docker pulls the image from Docker Hub when it is not available locally, then starts NGINX in the foreground. section 5.1.1
Add flags to connect the container to your machine and control how it runs:
- Publish a port with -p localPort:containerPort, such as docker run -p 8080:80 nginx, then visit localhost:8080. section 5.1.2
- Open an interactive shell with docker run -it nginx /bin/bash; inspect files with commands such as ls, then exit. section 5.1.3
- Run in the background with -d, inspect running containers with docker ps, view logs with docker logs, and stop one with docker stop. section 7.1.4
- Set a name with --name, remove an interactive container after use with --rm, or pass environment values with -e. section 5.2.2 section 5.4.2
Run NGINX locally and in the background
docker run -d --restart always --name my-nginx -p 80:80 nginx This starts NGINX from the nginx image, keeps it detached, publishes container port 80 on host port 80, assigns a predictable name, and configures automatic restart. section 7.1.4
See the minimal first-container command before adding ports, shells, names, and lifecycle flags. section 5.1.1



