Kitloft

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.

Customize names, versions →

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

Prefer Kubernetes? See the Nginx web server Kubernetes version.