Docker Deployment Guide
Brouillon : cette page n'a pas encore été relue et peut être incomplète ou inexacte.
This guide provides instructions for running the Kili Shops microservices using Docker.
Quick Start
Section intitulée « Quick Start »-
Build all services:
Fenêtre de terminal docker-compose build -
Start all services:
Fenêtre de terminal docker-compose up -d -
Verify services are running:
Fenêtre de terminal docker-compose ps -
Test the API:
Fenêtre de terminal curl http://localhost:3333# Should return: Hello World Gateway!
Architecture
Section intitulée « Architecture »The Docker setup includes:
- API Gateway (Port 3333) - Entry point for all HTTP requests
- Shops Microservice (Port 3001) - Manages shop data with MongoDB
- Users Microservice (Port 3002) - Manages user data with PostgreSQL
- MongoDB (Port 27018) - Database for shops
- PostgreSQL (Port 5433) - Database for users
All services run in an isolated Docker network and communicate using service names.
Service Ports
Section intitulée « Service Ports »| Service | Internal Port | External Port |
|---|---|---|
| API Gateway | 3000 | 3333 |
| Shops Service | 3001 | 3001 |
| Users Service | 3002 | 3002 |
| MongoDB | 27017 | 27018 |
| PostgreSQL | 5432 | 5433 |
Common Commands
Section intitulée « Common Commands »View Logs
Section intitulée « View Logs »# All servicesdocker-compose logs -f
# Specific servicedocker-compose logs -f api-gatewaydocker-compose logs -f shopsdocker-compose logs -f usersStop Services
Section intitulée « Stop Services »docker-compose downRebuild After Code Changes
Section intitulée « Rebuild After Code Changes »# Rebuild specific servicedocker-compose build shopsdocker-compose up -d shops
# Rebuild all servicesdocker-compose builddocker-compose up -dClean Up (Remove volumes)
Section intitulée « Clean Up (Remove volumes) »docker-compose down -vTesting the API
Section intitulée « Testing the API »Using cURL
Section intitulée « Using cURL »Test Gateway:
curl http://localhost:3333/Get All Shops:
curl http://localhost:3333/shopsCreate a Shop:
curl -X POST http://localhost:3333/shops/create \ -H "Content-Type: application/json" \ -d '{ "name": "My Shop", "description": "A great shop", "address": "123 Main St" }'Get All Users:
curl http://localhost:3333/usersCreate a User:
curl -X POST http://localhost:3333/users \ -H "Content-Type: application/json" \ -d '{ "name": "John Doe", "email": "john@example.com", "password": "password123", "phone": "+243123456789" }'Using Postman
Section intitulée « Using Postman »- Import the collection:
Kili-Shops-Microservices.postman_collection.json - The base URL is already set to
http://localhost:3333 - Run individual requests or entire test flows
- Test scenarios include automated assertions
Troubleshooting
Section intitulée « Troubleshooting »Port Already in Use
Section intitulée « Port Already in Use »If you see “port is already allocated” errors:
-
Check what’s using the port:
Fenêtre de terminal lsof -i :3333 # or whatever port is in use -
Stop the conflicting service or change the port in
docker-compose.yml
Service Not Starting
Section intitulée « Service Not Starting »Check the logs:
docker-compose logs [service-name]Common issues:
- Database not ready: Wait a few seconds and check again
- Build errors: Run
docker-compose buildagain - Network issues: Run
docker-compose downand restart
Database Connection Issues
Section intitulée « Database Connection Issues »If microservices can’t connect to databases:
-
Check if databases are healthy:
Fenêtre de terminal docker-compose ps -
Verify database logs:
Fenêtre de terminal docker-compose logs mongodbdocker-compose logs postgres -
Restart the services:
Fenêtre de terminal docker-compose restart shops users
Data Persistence
Section intitulée « Data Persistence »Data is stored in Docker volumes:
mongodb_data- Shop datapostgres_data- User data
To reset databases:
docker-compose down -vdocker-compose up -dDevelopment Workflow
Section intitulée « Development Workflow »- Make code changes
- Rebuild affected service:
Fenêtre de terminal docker-compose build [service-name] - Restart the service:
Fenêtre de terminal docker-compose up -d [service-name] - Check logs for errors:
Fenêtre de terminal docker-compose logs -f [service-name]
Production Considerations
Section intitulée « Production Considerations »Before deploying to production:
- Environment Variables: Update environment variables in docker-compose.yml
- Security:
- Change default database passwords
- Use secrets management
- Enable authentication on databases
- Networking: Use proper network configuration
- Monitoring: Add health check endpoints and monitoring
- Scaling: Consider using Docker Swarm or Kubernetes
- Backups: Set up automated database backups
API Endpoints
Section intitulée « API Endpoints »GET /- Health check
GET /shops- Get all shopsPOST /shops/create- Create a new shop
GET /users- Get all usersGET /users/:id- Get user by IDPOST /users- Create a new userPUT /users/:id- Update userDELETE /users/:id- Delete user
For issues or questions:
- Check the logs:
docker-compose logs -f - Review CLAUDE.md for architecture details
- Verify all services are healthy:
docker-compose ps