1.8 KiB
Docker Configuration Design
Goal
Add Docker support for both production deployment and local development of the Vite React app, while making the default production path minimize Docker downloads.
Architecture
Production builds the static app on the host using the already-installed npm dependencies, then uses a single-stage nginx:stable-alpine3.23-slim Dockerfile to copy and serve dist on port 80. This avoids downloading a Node image and reinstalling npm packages during the Docker deployment.
Development remains an optional separate Dockerfile and compose file. It installs dependencies, runs npm run dev, exposes Vite on port 3000, and mounts source files from the host while keeping node_modules inside the container. It is not the low-download production path.
Files
.dockerignoreexcludes dependencies, unrelated build output, logs, and local env files from Docker build context, while retainingdistfor the production image.Dockerfilecreates a small production image from the host-built static output.nginx.confserves static assets and falls back toindex.htmlfor React Router routes.docker-compose.ymlruns the production image on host port8080.Dockerfile.devruns the Vite dev server.docker-compose.dev.ymlruns the development container on host port3000.README.mddocuments the Docker commands.
Environment
The current Vite config injects GEMINI_API_KEY during build. Production therefore reads .env.local during the host-side npm run build command and copies the resulting static bundle into the container. Development reads environment values from .env.local when present.
Verification
- Run
npm run lint. - Run
npm run build. - Build the production Docker image after a host-side
npm run build. - Optionally run the compose services if Docker is available.