All tools / Docker Compose examples
Nginx web server with Docker Compose
Nginx serving files from a local folder with a custom config inline in the Compose file.
compose.yaml
services:
web:
image: nginx:1.28
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html:ro
configs:
- source: nginx_conf
target: /etc/nginx/conf.d/default.conf
configs:
nginx_conf:
content: |
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
location / {
try_files $$uri $$uri/ /index.html;
}
location = /healthz {
access_log off;
return 200 "ok";
}
}
How to use it
Commands
docker compose up -d docker compose ps docker compose logs -f
- Put your site in a folder named html next to compose.yaml, then open http://localhost:8080.
- The $$ in the nginx config stops Compose from reading $uri as one of its own variables.
Prefer Kubernetes? See the Nginx web server Kubernetes version.