Module 1: Docker for Java (The Shipping Container)
📚 Module 1: Docker for Java
Focus: Moving from “My Computer” to “Any Computer.”
In the professional world, we don’t just send our .jar files to the server. We wrap them in a Shipping Container called Docker.
🏗️ Step 1: The “It Works on My Machine” Problem
Imagine you build a beautiful piece of furniture.
- It works perfectly in your studio.
- But when you ship it to a friend, it breaks because their floor is uneven or their humidity is different.
- In Java: Your app might fail because the server has the wrong version of Java or a missing library.
🏗️ Step 2: Docker (The “Box”)
Docker is a high-tech shipping container that contains:
- The App: Your Java
.jarfile. - The OS: A tiny version of Linux.
- The Runtime: The Java JVM.
🧩 The Analogy: The Global Shipping Container
- No matter if the ship is a Truck, a Train, or a Boat, the Container is the exact same size and shape.
- The furniture inside doesn’t even know it’s moving. It always sees the same “Floor” and “Humidity.”
🏗️ Step 3: The Dockerfile (The “Blueprint”)
To build a container, you write a tiny recipe file.
📝 The Recipe:
- FROM: “Start with a clean room that has Java 21.”
- COPY: “Bring my furniture (the JAR) into the room.”
- CMD: “Start the app as soon as the door opens.”
In Code:
FROM eclipse-temurin:21-jre
COPY target/myapp.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]🥅 Module 1 Review
- Docker: A tool for packaging apps into portable containers.
- Image: The “Blueprints” for your box.
- Container: The “Real Box” that is currently running.
- Dockerfile: The script that builds the image.