Repository: https://github.com/godququ5-code/docker-node-assignment
This repository demonstrates how to deploy a Node.js backend with Docker and how to run a React client and Node.js server together with Docker Compose.
.
├── backend/ # Express API server
├── client/ # React + Vite client served by Nginx
├── docker-compose.yml # Runs client and server together
└── README.md # Assignment report and commands
- Docker tutorial: https://www.docker.com/blog/getting-started-with-docker-using-node-jspart-i/
- Node.js Docker guide: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
- Docker hello-world example: https://www.bogotobogo.com/DevOps/Docker/Docker_Hello_World_Application.php
- Client/server Compose example: https://medium.com/@xiaolishen/develop-in-docker-a-node-backend-and-a-react-front-end-talking-to-each-other-5c522156f634
Install Docker Desktop from the official Docker documentation:
https://docs.docker.com/desktop/
On macOS, Docker can also be provided by Docker CLI plus Colima:
brew install docker docker-compose colima
mkdir -p ~/.docker
node -e "const fs=require('fs'); const p=process.env.HOME+'/.docker/config.json'; const cfg=fs.existsSync(p)?JSON.parse(fs.readFileSync(p,'utf8')||'{}'):{}; cfg.cliPluginsExtraDirs=[...new Set([...(cfg.cliPluginsExtraDirs||[]), '/opt/homebrew/lib/docker/cli-plugins'])]; fs.writeFileSync(p, JSON.stringify(cfg, null, 2));"
colima startAfter installation, verify Docker:
docker --version
docker compose version
docker run hello-worldBuild the backend image:
docker build -t docker-node-backend ./backendRun the backend container:
docker run -d --name docker-node-backend-check -p 3000:3000 docker-node-backendCheck that the backend works:
curl http://localhost:3000/api/health
curl http://localhost:3000/api/messagesStop container execution:
docker stop docker-node-backend-check
docker rm docker-node-backend-checkBuild and start both containers:
docker compose up --build -dOpen the client:
http://localhost:8081
Check communication through the client container and Nginx proxy:
curl http://localhost:8081/api/health
curl http://localhost:8081/api/messagesThe client container serves the React app with Nginx. Requests to /api/ are proxied to the server container by using the Compose service name:
proxy_pass http://server:3000/api/;Stop the system:
docker compose downBackend:
cd backend
npm install
npm startClient:
cd client
npm install
npm run devThe Vite development server proxies /api requests to http://localhost:3000.
- Backend API is available at
http://localhost:3000/api/health. - React client is available at
http://localhost:8081. - The client can read backend status, list messages, and send new messages.
docker compose downstops and removes both containers.