Từ thư mục gốc project (bookstore-microservice05):
docker-compose up --buildLần đầu sẽ build image và chạy 5 service. Để chạy nền (detach):
docker-compose up --build -dMỗi service dùng SQLite riêng, cần tạo bảng một lần:
# Customer
docker-compose exec customer-service python manage.py migrate
# Book
docker-compose exec book-service python manage.py migrate
# Cart
docker-compose exec cart-service python manage.py migrate
# Staff
docker-compose exec staff-service python manage.py migrate(Gateway không có app với model nên có thể bỏ qua migrate.)
| Dịch vụ | URL (trình duyệt / API) |
|---|---|
| API Gateway (Web UI) | http://localhost:8000 |
| Customer API | http://localhost:8001 |
| Book API | http://localhost:8002 |
| Cart API | http://localhost:8003 |
| Staff API | http://localhost:8004 |
Trang qua Gateway (port 8000):
- Sách: http://localhost:8000/books/
- Giỏ hàng (theo customer id): http://localhost:8000/cart/1/
- Nhân viên: http://localhost:8000/staff/
Dừng hệ thống:
docker-compose down- Tạo venv, cài dependencies trong từng thư mục:
customer-service,book-service,cart-service,staff-service,api-gateway. - Chạy migrate trong từng service có model.
- Chạy server trên port khác nhau (ví dụ 8001, 8002, 8003, 8004, 8000).
- Trong
api-gateway(và các service gọi lẫn nhau), đổi URL sanghttp://localhost:PORTthay vìhttp://tên-service:8000(vì không có Docker network).