Serve Static Sites with Nginx + Docker

Problem

Need to quickly serve a built static site locally or on a server. Setting up a Node.js server is overkill.

Solution

# docker-compose.yml
version: '3'
services:
  nginx:
    image: nginx
    ports:
      - "80:80"
    volumes:
      - ./dist:/usr/share/nginx/html:ro
docker compose up -d

That’s it. Put your build output in ./dist and access it at http://localhost.

Key Points

  • The :ro (read-only) mount flag prevents accidental file modifications from inside the container. Always use it in production.
  • The official Nginx image defaults to /usr/share/nginx/html as the document root, so it works without any custom configuration files.
  • If you need SPA routing, add try_files $uri $uri/ /index.html; in a custom nginx.conf. Until then, this minimal setup is sufficient.