DevOps-Containerization

Docker Experiment: Containerizing a Java Application (Windows Environment)


Overview

This practical session demonstrates how to containerize a simple Java application using Docker. The experiment covers writing a Dockerfile, building a custom image, running a container, and verifying successful execution. The objective is to understand how Docker packages applications along with their runtime dependencies to ensure portability and consistency.


Aim

To create a Docker image for a Java application using a Dockerfile, build the image, and execute it successfully inside a container.


Tools & Technologies Used


Project Structure

Class Practical 28 Jan/ │ ├── Container-Codes/ │ ├── Dockerfile │ └── Hello.java


Java Source Code (Hello.java)

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, Docker!");
    }
}

Dockerfile Configuration

FROM ubuntu:22.04

RUN apt update && apt install -y openjdk-17-jdk

WORKDIR /home/app

COPY Hello.java .

RUN javac Hello.java

CMD ["java", "Hello"]

Step-by-Step Execution

Build Docker Image

docker build -t java-app:1.0 .

Explanation:


Verify Image Creation

docker images

Run the Container

docker run java-app:1.0

Expected Output:

Hello, Docker!

Key Docker Concepts Demonstrated


Result


Conclusion

This experiment illustrates how Docker encapsulates an application along with its runtime and dependencies into a portable image. By containerizing the Java program, we ensured environment consistency, simplified deployment, and improved application portability across systems.

Docker plays a crucial role in modern DevOps practices by enabling lightweight virtualization, scalable deployments, and reproducible environments.