Aller au contenu

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.

  1. Build all services:

    Fenêtre de terminal
    docker-compose build
  2. Start all services:

    Fenêtre de terminal
    docker-compose up -d
  3. Verify services are running:

    Fenêtre de terminal
    docker-compose ps
  4. Test the API:

    Fenêtre de terminal
    curl http://localhost:3333
    # Should return: Hello World Gateway!

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 Internal Port External Port
API Gateway 3000 3333
Shops Service 3001 3001
Users Service 3002 3002
MongoDB 27017 27018
PostgreSQL 5432 5433
Fenêtre de terminal
# All services
docker-compose logs -f
# Specific service
docker-compose logs -f api-gateway
docker-compose logs -f shops
docker-compose logs -f users
Fenêtre de terminal
docker-compose down
Fenêtre de terminal
# Rebuild specific service
docker-compose build shops
docker-compose up -d shops
# Rebuild all services
docker-compose build
docker-compose up -d
Fenêtre de terminal
docker-compose down -v

Test Gateway:

Fenêtre de terminal
curl http://localhost:3333/

Get All Shops:

Fenêtre de terminal
curl http://localhost:3333/shops

Create a Shop:

Fenêtre de terminal
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:

Fenêtre de terminal
curl http://localhost:3333/users

Create a User:

Fenêtre de terminal
curl -X POST http://localhost:3333/users \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "password123",
"phone": "+243123456789"
}'
  1. Import the collection: Kili-Shops-Microservices.postman_collection.json
  2. The base URL is already set to http://localhost:3333
  3. Run individual requests or entire test flows
  4. Test scenarios include automated assertions

If you see “port is already allocated” errors:

  1. Check what’s using the port:

    Fenêtre de terminal
    lsof -i :3333 # or whatever port is in use
  2. Stop the conflicting service or change the port in docker-compose.yml

Check the logs:

Fenêtre de terminal
docker-compose logs [service-name]

Common issues:

  • Database not ready: Wait a few seconds and check again
  • Build errors: Run docker-compose build again
  • Network issues: Run docker-compose down and restart

If microservices can’t connect to databases:

  1. Check if databases are healthy:

    Fenêtre de terminal
    docker-compose ps
  2. Verify database logs:

    Fenêtre de terminal
    docker-compose logs mongodb
    docker-compose logs postgres
  3. Restart the services:

    Fenêtre de terminal
    docker-compose restart shops users

Data is stored in Docker volumes:

  • mongodb_data - Shop data
  • postgres_data - User data

To reset databases:

Fenêtre de terminal
docker-compose down -v
docker-compose up -d
  1. Make code changes
  2. Rebuild affected service:
    Fenêtre de terminal
    docker-compose build [service-name]
  3. Restart the service:
    Fenêtre de terminal
    docker-compose up -d [service-name]
  4. Check logs for errors:
    Fenêtre de terminal
    docker-compose logs -f [service-name]

Before deploying to production:

  1. Environment Variables: Update environment variables in docker-compose.yml
  2. Security:
    • Change default database passwords
    • Use secrets management
    • Enable authentication on databases
  3. Networking: Use proper network configuration
  4. Monitoring: Add health check endpoints and monitoring
  5. Scaling: Consider using Docker Swarm or Kubernetes
  6. Backups: Set up automated database backups
  • GET / - Health check
  • GET /shops - Get all shops
  • POST /shops/create - Create a new shop
  • GET /users - Get all users
  • GET /users/:id - Get user by ID
  • POST /users - Create a new user
  • PUT /users/:id - Update user
  • DELETE /users/:id - Delete user

For issues or questions:

  1. Check the logs: docker-compose logs -f
  2. Review CLAUDE.md for architecture details
  3. Verify all services are healthy: docker-compose ps