Skip to content

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:

  1. The App: Your Java .jar file.
  2. The OS: A tiny version of Linux.
  3. 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:

  1. FROM: “Start with a clean room that has Java 21.”
  2. COPY: “Bring my furniture (the JAR) into the room.”
  3. 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

  1. Docker: A tool for packaging apps into portable containers.
  2. Image: The “Blueprints” for your box.
  3. Container: The “Real Box” that is currently running.
  4. Dockerfile: The script that builds the image.