Multi-stage Dockerfile builds the Vite app in Node 22 and serves static assets from nginx:alpine. Includes gzip compression, SPA fallback routing, immutable cache headers for hashed assets, and configurable port mapping (default 8080). Deploy with `docker compose up -d`.
1.3 KiB
1.3 KiB
1. Docker Ignore
- 1.1 Create
.dockerignoreat project root excludingnode_modules,.git,dist,openspec, and*.md
2. Nginx Configuration
- 2.1 Create
nginx.confat project root with: gzip enabled for text/html, CSS, JS, JSON; SPA fallback viatry_files $uri $uri/ /index.html;Cache-Control: public, max-age=31536000, immutablefor/assets/;Cache-Control: no-cachefor root/index.html; listen on port 80
3. Dockerfile
- 3.1 Create multi-stage
Dockerfileat project root — stage 1:node:22-alpine, copyapp/, install deps, runnpm run build; stage 2:nginx:alpine, copy builtdist/to nginx html dir, copynginx.conf
4. Docker Compose
- 4.1 Create
docker-compose.ymlat project root with a singleappservice that builds from the Dockerfile and maps host port 8080 to container port 80
5. Verification
- 5.1 Run
docker compose buildand verify the image builds successfully - 5.2 Run
docker compose up -dand verify the app is accessible athttp://localhost:8080 - 5.3 Verify gzip compression is active on JS/CSS responses
- 5.4 Verify cache headers: immutable on
/assets/*, no-cache on/ - 5.5 Verify SPA fallback: request a non-existent path and confirm index.html is returned