| name | dockerfile-angular-correct-usage |
| description | Use this skill when building Docker images for Angular applications to ensure efficient, secure, and production-ready deployments. |
When building Docker images for Angular:
-
Use multi-stage builds:
- build stage → compile Angular app (Node image)
- runtime stage → serve static files (Nginx or similar)
-
Base images:
- build stage: node:lts-alpine
- runtime stage: nginx:alpine
-
Build rules:
- run
npm ci instead of npm install
- use production build (
ng build --configuration production)
- output to
/dist
-
Runtime rules:
- serve static files via Nginx
- configure fallback to
index.html for SPA routing
- remove default Nginx config and replace with custom one
-
Security:
- avoid unnecessary packages in final image
- use minimal base images (alpine)
- do not include source code in runtime image
- do not store secrets in the image
-
Ports:
- expose port 80 (or configured Nginx port)
-
Configuration:
- use environment variables for runtime config when needed
- avoid hardcoding API URLs in build when flexibility is required
-
Caching optimization:
- copy package.json/package-lock.json first
- install dependencies before copying full source
- leverage Docker layer caching
-
Image tagging:
- use semantic versioning (MAJOR.MINOR.PATCH)
- optionally include build metadata (e.g. commit SHA)
-
Reproducibility:
- ensure consistent builds via lock files
- avoid non-deterministic installs
-
Avoid:
- single-stage Dockerfiles
- using
npm install in production builds
- shipping development dependencies
- exposing Node server for static Angular apps
- embedding secrets or environment-specific configs
Docker images must be minimal, reproducible, and optimized for static delivery.
Always prioritize performance, caching efficiency, and security.