Skip to content

Commit 101c370

Browse files
Merge pull request #6 from Lhloworld/main
Containerization of App using Docker
2 parents b369417 + 51fcbea commit 101c370

27 files changed

+143
-8
lines changed

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
target/
2+
.mvn/
3+
.idea/
4+
*.iml
5+
.classpath
6+
.project
7+
.settings/
8+
.git/
9+
node_modules/
10+
logs/
11+
*.log

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.compile.nullAnalysis.mode": "automatic"
3+
}

Docker-README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Inventory Management Tool - Docker Setup
2+
3+
This project is a Spring Boot application. The repository includes a multi-stage `Dockerfile` that builds the app with Maven and produces a runtime image. A `docker-compose.yml` is provided to run the service together with a MySQL database.
4+
5+
---
6+
7+
## Quick Commands
8+
9+
```bash
10+
# Build Docker image
11+
docker build -t im-app:latest .
12+
13+
# Run the Docker image
14+
docker run --rm -p 8082:8082 \
15+
-e SPRING_DATASOURCE_URL='jdbc:mysql://<host>:3306/inventory_db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC' \
16+
-e SPRING_DATASOURCE_USERNAME=root \
17+
-e SPRING_DATASOURCE_PASSWORD=Anjana@3176 \
18+
im-app:latest
19+
20+
# Start using Docker Compose
21+
docker compose up --build
22+
23+
# Stop Docker Compose
24+
docker compose down
25+
26+
# View logs
27+
docker compose logs -f

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ---------- STAGE 1: Build ----------
2+
FROM maven:3.9.8-eclipse-temurin-21 AS builder
3+
WORKDIR /app
4+
5+
COPY pom.xml .
6+
RUN mvn dependency:go-offline
7+
8+
COPY src ./src
9+
RUN mvn clean package -DskipTests
10+
11+
# ---------- STAGE 2: Runtime ----------
12+
FROM eclipse-temurin:21-jdk
13+
WORKDIR /app
14+
15+
# Install netcat (for wait-for-it.sh)
16+
RUN apt-get update && apt-get install -y netcat-openbsd && rm -rf /var/lib/apt/lists/*
17+
18+
# Copy jar and wait script
19+
COPY --from=builder /app/target/*.jar app.jar
20+
COPY wait-for-it.sh .
21+
RUN chmod +x wait-for-it.sh
22+
23+
EXPOSE 8082
24+
25+
ENTRYPOINT ["java", "-jar", "app.jar"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ spring.datasource.username=your_username
4545

4646
spring.datasource.password=your_password
4747

48+
🌏 Docker Hub Image
49+
50+
You can directly pull and run the pre-built image from Docker Hub:
51+
52+
docker pull atulsingh17/opcode-inventorymanagement:1.0
53+
docker run -p 8080:8082 atulsingh17/opcode-inventorymanagement:1.0
4854

4955
3. **Build and run**
5056
```bash

docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: "3.9"
2+
3+
services:
4+
db:
5+
image: mysql:8.0
6+
container_name: mysql-db
7+
environment:
8+
MYSQL_ROOT_PASSWORD: Anjana@3176
9+
MYSQL_DATABASE: inventory_db
10+
# MYSQL_USER: root
11+
# MYSQL_PASSWORD: Anjana@3176
12+
#ports:
13+
# - "3306:3306"
14+
volumes:
15+
- mysql_data:/var/lib/mysql
16+
healthcheck:
17+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-pAnjana@3176"]
18+
interval: 5s
19+
timeout: 10s
20+
retries: 10
21+
22+
app:
23+
build: .
24+
container_name: inventory-app
25+
depends_on:
26+
db:
27+
condition: service_healthy
28+
environment:
29+
SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/inventory_db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
30+
SPRING_DATASOURCE_USERNAME: root
31+
SPRING_DATASOURCE_PASSWORD: Anjana@3176
32+
ports:
33+
- "8080:8082"
34+
command: ["./wait-for-it.sh", "db", "3306", "--", "java", "-jar", "app.jar"]
35+
36+
volumes:
37+
mysql_data:
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Database
2-
spring.datasource.url=jdbc:mysql://localhost:3306/inventory_db?allowPublicKeyRetrieval=true&useSSL=false
2+
spring.datasource.url=jdbc:mysql://db:3306/inventory_db?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC
33
spring.datasource.username=root
44
spring.datasource.password=Anjana@3176
55

@@ -11,10 +11,3 @@ spring.jpa.properties.hibernate.format_sql=true
1111

1212
# Server
1313
server.port=8082
14-
15-
16-
# JWT
17-
#abhay
18-
# jwt.secret=your-secret-key
19-
# jwt.expiration=86400000 # 24 hours in milliseconds
20-
#lol
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Database
2+
spring.datasource.url=jdbc:mysql://db:3306/inventory_db?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC
3+
spring.datasource.username=root
4+
spring.datasource.password=Anjana@3176
5+
6+
# JPA/Hibernate
7+
spring.jpa.hibernate.ddl-auto=update
8+
spring.jpa.show-sql=true
9+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
10+
spring.jpa.properties.hibernate.format_sql=true
11+
12+
# Server
13+
server.port=8082
727 Bytes
Binary file not shown.
5.97 KB
Binary file not shown.

0 commit comments

Comments
 (0)