This repository contains a multi-service application using Docker Compose, featuring the following components:
- Zookeeper: Manages the Kafka cluster.
- Kafka: Messaging broker for communication between microservices.
- Auth Service: Handles user authentication and authorization.
- User Management Service: Manages user data and profiles.
Before running the application, ensure you have the following installed:
- Docker: Install Docker
- Docker Compose: Install Docker Compose
- Purpose: Manages the Kafka cluster's metadata.
- Port:
2181 - Image:
confluentinc/cp-zookeeper:latest
- Purpose: Message broker used for communication between microservices.
- Port:
9092 - Image:
confluentinc/cp-kafka:latest
- Purpose: Handles user authentication and authorization.
- Port:
9000 - Custom Image:
viraj179/auth-service:latest
- Purpose: Manages user profiles and data.
- Port:
9010 - Custom Image:
viraj179/user-management-service:latest
Clone the repository and navigate to the project directory:
git clone https://github.com/SoftGrid2/ems.git
cd ems
docker pull confluentinc/cp-zookeeper:latest
docker pull confluentinc/cp-kafka:latest
docker pull viraj179/nlss-auth-service:latest
docker pull viraj179/nlss-user-management-service:latest
---
## Step 1: Start the application
docker-compose up -d
### Step 2: Verify Running Containers
docker ps
### Step 3: You should see the following containers:
zookeeper
kafka
auth-service
user-management
### Notes
Ensure Zookeeper starts before Kafka.
Kafka must be running for auth-service and user-management-service to work properly.
The services communicate internally through the kafka-network defined as a bridge network.
This guide provides steps to query databases running in Docker containers for both auth-service and user-management services.
- Docker and Docker Compose installed on your machine.
- PostgreSQL client installed locally (optional for direct host access).
- Databases
auth-serviceanduser-managementrunning in Docker containers.
-
Find the running container for
auth-service:docker ps
-
Access the PostgreSQL database inside the
auth-servicecontainer:docker exec -it postgres-auth-service psql -U postgres -d auth-service -
Verify tables in the database:
\dt
-
View data in the
userstable:SELECT * FROM users LIMIT 10;
-
Count total users:
SELECT COUNT(*) FROM users;
-
Insert a sample user:
INSERT INTO users (email, password, role, name, created_at, updated_at) VALUES ('example@example.com', 'securepassword', 'Admin', 'John Doe', NOW(), NOW());
-
Find the running container for
user-management:docker ps
-
Access the PostgreSQL database inside the
user-managementcontainer:docker exec -it postgres-user-management psql -U postgres -d user-management -
Verify tables in the database:
\dt
-
View data in the
userstable:SELECT * FROM users LIMIT 10;
-
Insert a sample user:
INSERT INTO users (email, password, name, created_at, updated_at) VALUES ('jane.doe@example.com', 'securepassword', 'Jane Doe', NOW(), NOW());
-
Delete a user by ID:
DELETE FROM users WHERE id = 1;
-
Exporting a Database:
docker exec -it postgres-auth-service pg_dump -U postgres auth-service > auth-service.sql
-
Restoring a Database:
docker exec -i postgres-auth-service psql -U postgres auth-service < auth-service.sql
-
Backup for
user-management:docker exec -it postgres-user-management pg_dump -U postgres user-management > user-management.sql
-
Error: Relation does not exist
- Verify the correct database is selected.
- Check if the tables were created properly using
\dt.
-
Connection Issues
- Ensure environment variables (
DB_HOST,DB_PORT,DB_USER,DB_PASSWORD,DB_NAME) are correctly set. - Restart containers to apply changes:
docker-compose restart
- Ensure environment variables (
-
Check Logs
docker logs postgres-auth-service docker logs postgres-user-management
-
List all databases:
\l
-
Describe a table:
\d table_name
-
Exit PostgreSQL:
\q -
Exit docker_container:
exit