DevOps-Containerization

Dockerfile Creation & Custom Image Building (Windows Environment)


Overview

This practical session demonstrates the complete workflow of creating, building, managing, exporting, importing, and deploying a custom Docker image using a Dockerfile. The experiment focuses on understanding Dockerfile instructions, Docker image layering architecture, and application containerization using Java.


Objectives


Tools & Technologies Used


Project Structure

Class Practical 30 Jan/ │ ├── Hello.java ├── Dockerfile ├── java-app.tar └── README.md


Java Application Source Code

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello from Java inside Docker on Windows!");
    }
}

Dockerfile Configuration

# Base Image
FROM ubuntu:22.04

# Update system and install Java
RUN apt update && apt install -y openjdk-17-jdk

# Set working directory
WORKDIR /app

# Copy source code
COPY Hello.java .

# Compile Java program
RUN javac Hello.java

# Default container execution command
CMD ["java", "Hello"]

Build Docker Image

docker build -t java-app:1.0 .

Verify image:

docker images

Run Container from Image

docker run java-app:1.0

Expected Output:

Hello from Java inside Docker on Windows!


Manage Containers & Images

List containers:

docker ps -a

Remove container:

docker rm <container-id>

Remove image:

docker rmi java-app:1.0

Export Docker Image

docker save -o java-app.tar java-app:1.0

Load Docker Image

docker load -i java-app.tar

Push Image to Docker Hub

Login:

docker login

Tag image:

docker tag java-app:1.0 YOUR_DOCKERHUB_USERNAME/java-app:1.0

Push image:

docker push YOUR_DOCKERHUB_USERNAME/java-app:1.0

Understanding Docker Layer Architecture


DevOps Application Packaging Workflow

  1. Write application source code.
  2. Define environment using Dockerfile.
  3. Build Docker image.
  4. Test application in container.
  5. Version and tag image.
  6. Export or push image to Docker Hub.
  7. Deploy image in any environment consistently.

Result


Conclusion

This experiment provided practical understanding of Dockerfile-based image creation, container execution, and DevOps application packaging workflows. It demonstrated how Docker ensures environment consistency, portability, and scalable deployment through containerization.