Skip to content

Commit 6403cbe

Browse files
committed
added Dockerfile in each service layer, so that docker-compose.yml can create docker images of these services in one go
1 parent f765e04 commit 6403cbe

5 files changed

Lines changed: 123 additions & 0 deletions

File tree

‎api-gateway/Dockerfile‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 1. Use an official Java runtime as a parent image
2+
FROM eclipse-temurin:17-jdk-alpine
3+
4+
# 2. Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# 3. Copy the compiled jar file into the container
8+
# We use a wildcard (*.jar) so you don't have to worry about version numbers
9+
COPY target/*.jar app.jar
10+
11+
# 4. Run the jar file
12+
ENTRYPOINT ["java", "-jar", "app.jar"]

‎booking-service/Dockerfile‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 1. Use an official Java runtime as a parent image
2+
FROM eclipse-temurin:17-jdk-alpine
3+
4+
# 2. Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# 3. Copy the compiled jar file into the container
8+
# We use a wildcard (*.jar) so you don't have to worry about version numbers
9+
COPY target/*.jar app.jar
10+
11+
# 4. Run the jar file
12+
ENTRYPOINT ["java", "-jar", "app.jar"]

‎discovery-server/Dockerfile‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 1. Use an official Java runtime as a parent image
2+
FROM eclipse-temurin:17-jdk-alpine
3+
4+
# 2. Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# 3. Copy the compiled jar file into the container
8+
# We use a wildcard (*.jar) so you don't have to worry about version numbers
9+
COPY target/*.jar app.jar
10+
11+
# 4. Run the jar file
12+
ENTRYPOINT ["java", "-jar", "app.jar"]

‎docker-compose.yml‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
version: '3.8'
2+
3+
services:
4+
# ----------------------------
5+
# 1. THE BRAIN (Eureka Server)
6+
# ----------------------------
7+
discovery-server:
8+
image: discovery-server:latest
9+
container_name: discovery-server
10+
build: ./discovery-server # Tells Docker where to find the Dockerfile
11+
ports:
12+
- "8761:8761" # Maps Localhost:8761 -> Container:8761
13+
environment:
14+
- SPRING_APPLICATION_NAME=discovery-server
15+
networks:
16+
- microservices-net
17+
18+
# ----------------------------
19+
# 2. THE GATEKEEPER (API Gateway)
20+
# ----------------------------
21+
api-gateway:
22+
image: api-gateway:latest
23+
container_name: api-gateway
24+
build: ./api-gateway
25+
ports:
26+
- "8080:8080" # This is the ONLY entry point for users
27+
environment:
28+
- SPRING_APPLICATION_NAME=api-gateway
29+
# The MAGIC: We tell it Eureka is at "http://discovery-server" (not localhost)
30+
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://discovery-server:8761/eureka/
31+
depends_on:
32+
- discovery-server
33+
networks:
34+
- microservices-net
35+
36+
# ----------------------------
37+
# 3. BOOKING SERVICE
38+
# ----------------------------
39+
booking-service:
40+
image: booking-service:latest
41+
container_name: booking-service
42+
build: ./booking-service
43+
ports:
44+
- "8081:8080" # Optional: access directly via localhost:8081 if needed
45+
environment:
46+
- SPRING_APPLICATION_NAME=booking-service
47+
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://discovery-server:8761/eureka/
48+
depends_on:
49+
- discovery-server
50+
- api-gateway
51+
networks:
52+
- microservices-net
53+
54+
# ----------------------------
55+
# 4. EVENT SERVICE
56+
# ----------------------------
57+
event-service:
58+
image: event-service:latest
59+
container_name: event-service
60+
build: ./event-service
61+
ports:
62+
- "8082:8080" # Optional: access directly via localhost:8082 if needed
63+
environment:
64+
- SPRING_APPLICATION_NAME=event-service
65+
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://discovery-server:8761/eureka/
66+
depends_on:
67+
- discovery-server
68+
- api-gateway
69+
networks:
70+
- microservices-net
71+
72+
# Create a shared network so they can talk to each other
73+
networks:
74+
microservices-net:
75+
driver: bridge

‎event-service/Dockerfile‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 1. Use an official Java runtime as a parent image
2+
FROM eclipse-temurin:17-jdk-alpine
3+
4+
# 2. Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# 3. Copy the compiled jar file into the container
8+
# We use a wildcard (*.jar) so you don't have to worry about version numbers
9+
COPY target/*.jar app.jar
10+
11+
# 4. Run the jar file
12+
ENTRYPOINT ["java", "-jar", "app.jar"]

0 commit comments

Comments
 (0)