Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 1ca5ea3

Browse files
committed
Added docker file
1 parent cf79222 commit 1ca5ea3

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

examples/chatroom-java/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ target/
44
!**/src/test/**/target/
55

66
### IntelliJ IDEA ###
7-
# .idea/*
7+
.idea/*
88
*.iws
99
*.iml
1010
*.ipr

examples/chatroom-java/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Use OpenJDK 21 base image
2+
FROM openjdk:21-jdk
3+
4+
WORKDIR /app
5+
6+
COPY target/chatroom.jar .
7+
8+
ENTRYPOINT ["java", "-jar", "chatroom.jar"]
9+
CMD []

examples/chatroom-java/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ java -jar target/chatroom.jar <username1>
3030
java -jar target/chatroom.jar <username2>
3131
```
3232

33+
### Using Docker
34+
35+
To build and run the Container:
36+
37+
```bash
38+
# Step 1: Build the jar
39+
./mvnw clean install
40+
41+
# Step 2: Run DiceDB docker container first
42+
docker-compose up -d dicedb
43+
44+
# Step 3: Run Container for each chatroom session
45+
docker-compose run chatroom username1
46+
docker-compose run chatroom username2
47+
```
48+
3349
### Using IntelliJ (Not in windows)
3450

3551
```text
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '3.8'
2+
3+
services:
4+
dicedb:
5+
image: dicedb/dicedb:latest
6+
container_name: dicedb
7+
ports:
8+
- "7379:7379"
9+
10+
chatroom:
11+
build:
12+
context: .
13+
dockerfile: Dockerfile
14+
container_name: chatroom-app
15+
depends_on:
16+
- dicedb
17+
environment:
18+
- DICEDB_HOST=dicedb
19+
- DICEDB_PORT=7379
20+
stdin_open: true
21+
tty: true

examples/chatroom-java/src/main/java/me/vipulgupta/dice/example/DiceDbChatBackend.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class DiceDbChatBackend {
1313
String username;
1414

1515
DiceDbChatBackend(String username) throws DiceDbException, InterruptedException {
16-
this.diceDbManager = new DiceDbManager("localhost", 7379, 2, 2);
16+
String host = System.getenv("DICEDB_HOST") == null ? "localhost" : System.getenv("DICEDB_HOST");
17+
int port = System.getenv("DICEDB_PORT") == null ? 7379 : Integer.parseInt(System.getenv("DICEDB_PORT"));
18+
this.diceDbManager = new DiceDbManager(host, port, 2, 2);
1719
this.username = username;
1820
}
1921

0 commit comments

Comments
 (0)