Deploying Nginx Web Server with Docker
Start by pulling the official Nginx image from Docker Hub. The default tag retrieves the latest stable release optimized for general use:
docker pull nginx
For environments prioritizing minimal resource usage, use the Alpine Linux-based variant instead:
docker pull nginx:alpine
Confirm the image exists in your local registry:
docker image ls | grep nginx
Expected output includes repository details, image digests, and size differences between standard and Alpine builds.
Launch a detached container mapping host port 8080 to the standard HTTP port:
docker run -d \
--name http-gateway \
-p 8080:80 \
--restart unless-stopped \
nginx
The --restart policy ensures the service resumes after system reboots. For persistent custom configurations, mount configuration and content direcotries from the host filesystem:
docker run -d \
--name configured-proxy \
-v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro \
-v $(pwd)/html:/usr/share/nginx/html:ro \
-p 8080:80 \
nginx
Verify active containers filtering by the Nginx ancestor image:
docker ps --filter "ancestor=nginx" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
Access the deployment via http://localhost:8080 to view the default welcome page, confirming the web server operates correctly inside the containeirzed environment.
To discover available image variants including specific version tags:
docker search nginx --filter is-official=true --limit 5
This query returns official repositories suitable for production deployments, excluding community modifications.