Skip to content
Runbook

Install Nginx on Docker

High-performance web server, reverse proxy, load balancer and HTTP cache.

Toolweb-serverreverse-proxyload-balancerhttpproxy

Installation

Container (official image) · Docker
docker run -d --name nginx -p 8080:80 nginx

Publishes container port 80 on host port 8080. Browse http://localhost:8080.

Verify the installation

Verify
docker exec nginx nginx -v

Important files

TypePathDescription
config/etc/nginx/nginx.confMain configuration inside the container; mount your own to customize.
data/usr/share/nginx/htmlDefault document root inside the container; mount your site here.

Default ports

80

Command-line tools

  • nginxThe server binary inside the container; reload with docker exec nginx nginx -s reload.

Uninstall

Remove the container
docker rm -f nginx

Good to know

  • The container listens on port 80; map it to a host port with -p (here 8080:80).
  • Serve your own site by mounting it: -v $(pwd)/site:/usr/share/nginx/html:ro.
  • Provide a custom config with -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro, then docker exec nginx nginx -s reload.

Running Nginx with Docker

The official nginx image serves content out of the box. docker run -d --name nginx -p 8080:80 nginx runs a detached container and maps container port 80 to host port 8080; browse http://localhost:8080.

Serving your own site

Mount a directory over the default document root: -v $(pwd)/site:/usr/share/nginx/html:ro. The container picks up the files immediately — no rebuild needed for static content.

Custom configuration

Mount your own config with -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro. After editing it, apply changes without restarting via docker exec nginx nginx -s reload.