A small React/Vite app for teaching Docker single-stage and multi-stage builds.
- Dockerfile → Docker Image → Running Container
- Single-stage build: build and run in the same Node.js image
- Multi-stage build: build with Node.js, serve final files with NGINX
- Why multi-stage images are usually cleaner and smaller for production
docker-build-demo/
├── src/
│ ├── App.jsx
│ ├── main.jsx
│ └── style.css
├── Dockerfile.single
├── Dockerfile.multi
├── nginx.conf
├── package.json
└── index.html
docker build -f Dockerfile.single -t react-single:v1 .
docker run -d --name react-single -p 3001:4173 react-single:v1Open:
http://localhost:3001
docker build -f Dockerfile.multi -t react-multi:v1 .
docker run -d --name react-multi -p 3002:80 react-multi:v1Open:
http://localhost:3002
docker images | grep reactSingle-stage:
docker exec -it react-single sh
node -v
npm -v
ls
ls dist
exitMulti-stage:
docker exec -it react-multi sh
nginx -v
node -v
npm -v
ls /usr/share/nginx/html
exitIn the multi-stage container, node -v and npm -v should fail because the final image is NGINX only.