Skip to content

Commit b6f0db4

Browse files
committed
chore: setup docker compose
1 parent 83b47d5 commit b6f0db4

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

apps/README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# PeerPrep Docker Compose Guide
2+
3+
This project uses Docker Compose to manage multiple services such as a frontend, backend, and a database. The configuration is defined in the `docker-compose.yml` file, and environment variables can be stored in environment files for different environments (e.g., development, production).
4+
5+
## Prerequisites
6+
7+
Before you begin, ensure you have the following installed on your machine:
8+
9+
- [Docker](https://www.docker.com/get-started)
10+
- [Docker Compose](https://docs.docker.com/compose/install/)
11+
12+
## Project Structure
13+
14+
In the `./apps` directory:
15+
16+
```plaintext
17+
.
18+
├── docker-compose.yml # Docker Compose configuration
19+
├── .env # Global environment variables (optional)
20+
├── frontend
21+
│ ├── Dockerfile # Dockerfile for frontend
22+
│ └── ... (other frontend files)
23+
├── question-service
24+
│ ├── Dockerfile # Dockerfile for question-service
25+
│ └── ... (other question-service files)
26+
├── user-service
27+
│ ├── Dockerfile # Dockerfile for user-service
28+
│ └── ... (other user-service files)
29+
└── README.md # Project documentation (for docker compose)
30+
```
31+
32+
## Docker Compose Setup
33+
34+
By using multiple Dockerfiles in Docker Compose, we can manage complex multi-container applications where each service has its own environment and build process.
35+
36+
1. Build and Start the Application
37+
38+
To build and run both the frontend and backend services, you can change your directory to the `./apps` directory and run:
39+
40+
```bash
41+
docker-compose up --build
42+
```
43+
44+
This will:
45+
46+
- Build the Docker images for all services using the specified Dockerfiles
47+
- Start the containers and map the defined ports
48+
49+
2. Access the Application
50+
51+
Once running, you can access:
52+
53+
- The **frontend** at http://localhost:3000
54+
- The **user service** at http://localhost:3001
55+
- The **question service** at http://localhost:8080
56+
57+
3. Stopping Services
58+
59+
To stop the running services, run:
60+
61+
```bash
62+
docker-compose down
63+
```
64+
65+
This command will stop and remove the containers, networks, and volumes created by docker-compose up.
66+
67+
## Troubleshooting
68+
69+
**Common Issues**
70+
71+
- Port Conflicts: If you encounter port conflicts, ensure the host ports specified in docker-compose.yml (e.g., 3000:3000) are not in use by other applications.
72+
- Environment Variables Not Loaded: Ensure the `.env` files are in the correct directories as found in the `docker-compose.yml` file.
73+
74+
**Logs**
75+
76+
You can view the logs for each service using the following command:
77+
78+
```bash
79+
docker-compose logs
80+
```
81+
82+
**Useful Commands**
83+
84+
Rebuild a specific service:
85+
86+
```bash
87+
docker-compose build <service_name>
88+
```
89+
90+
Start services in detached mode (run in the background):
91+
92+
```bash
93+
docker-compose up -d
94+
```
95+
96+
Remove all containers, networks, and volumes created by Docker Compose:
97+
98+
```bash
99+
docker-compose down --volumes
100+
```

apps/docker-compose.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
services:
2+
frontend:
3+
build:
4+
context: ./frontend
5+
dockerfile: Dockerfile
6+
ports:
7+
- 3000:3000
8+
networks:
9+
- apps_network
10+
env_file:
11+
- ./frontend/.env
12+
volumes:
13+
- ./frontend:/frontend
14+
15+
user-service:
16+
build:
17+
context: ./user-service
18+
dockerfile: Dockerfile
19+
args:
20+
DB_CLOUD_URI: ${DB_CLOUD_URI}
21+
JWT_SECRET: ${JWT_SECRET}
22+
ports:
23+
- 3001:3001
24+
networks:
25+
- apps_network
26+
env_file:
27+
- ./user-service/.env
28+
volumes:
29+
- ./user-service:/user-service
30+
31+
question-service:
32+
build:
33+
context: ./question-service
34+
dockerfile: Dockerfile
35+
ports:
36+
- 8080:8080
37+
env_file:
38+
- ./question-service/.env
39+
networks:
40+
- apps_network
41+
volumes:
42+
- ./question-service:/question-service
43+
44+
networks:
45+
apps_network:

0 commit comments

Comments
 (0)