🐳 Docker: Simplifying Application Deployment
Docker is a containerization platform that helps you package, deploy, and run
applications in isolated environments called containers.
Instead of saying, "It works on my machine," Docker ensures it works everywhere
by bundling the application along with its dependencies, configurations, and
libraries into a single container.
🌐 Why Docker? (Real-World Scenario in Telecom) 📡
In your telecom project (Helix platform), you manage services like SIM Activation
and Plan Management.
Without Docker: Manual setup of Java, Spring Boot, MySQL on every
environment.
With Docker: Run all services consistently using docker-compose.
⚙️Key Docker Concepts (Simplified)
1. Image: Blueprint of the application (e.g., sim-service:1.0).
2. Container: Running instance of the image.
3. Dockerfile: Instructions to build the image.
4. Docker Compose: Manage multiple containers easily.
5. Volumes: Persistent storage for container data.
Step-by-Step Guide to Dockerize a Spring Boot Java Application 🚀
🔹 1️⃣ Create a Simple Spring Boot App
[Link]
@RestController
@RequestMapping("/api/sim")
public class SimController {
@GetMapping("/activate/{simNumber}")
public String activateSim(@PathVariable String simNumber) {
return "SIM " + simNumber + " activated successfully!";
}
}
[Link]
[Link]=8081
🔹 2️⃣ Create a Dockerfile 🐳
Dockerfile
# 1️⃣ Use an official OpenJDK base image
FROM openjdk:17-jdk-slim
# 2️⃣ Set the working directory
WORKDIR /app
# 3️⃣ Copy the JAR file into the container
COPY target/[Link] [Link]
# 4️⃣ Expose the application port
EXPOSE 8081
# 5️⃣ Run the application
ENTRYPOINT ["java", "-jar", "[Link]"]
🔹 3️⃣ Build and Run the Docker Image
1. Build the JAR:
2. mvn clean install
3. Build the Docker Image:
4. docker build -t sim-service:1.0 .
5. Run the Container:
6. docker run -d -p 8081:8081 sim-service:1.0
🔍 Check the Application:
Open: [Link]
⚙️4️⃣ Docker Compose for Multiple Microservices
[Link]
version: '3.8'
services:
sim-service:
image: sim-service:1.0
ports:
- "8081:8081"
environment:
- SPRING_PROFILES_ACTIVE=prod
plan-service:
image: plan-service:1.0
ports:
- "8082:8082"
mysql-db:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: telecom
ports:
- "3306:3306"
Run all services:
docker-compose up -d
⚡ Advantages of Docker 🌟
1. Portability: Run the app anywhere with Docker installed.
2. Isolation: Separate environments for different services.
3. Scalability: Easily scale services using Docker Swarm or Kubernetes.
4. Simplified Deployment: docker-compose automates multi-container
applications.
5. Consistency: Same environment across dev, staging, and production.
Would you like help with Dockerizing multiple microservices or deploying
Dockerized services to AWS ECS? 😊