Escape the Wastage: A Beginner’s Guide to Docker and Containerization

🌱 Just a fresher, vibin’ through tech life. ☁️ Cloud & DevOps rookie, tryna get my hands dirty with real stuff. 🛠️ Writing blogs in my own chill style ’cause most guides feel way too pro-level. 🚀 Learning, breaking, fixing, and sharing my journey—no sugarcoat, just raw curiosity.
Are you concerned about wasting your compute resources, not using them to their fullest capacity? Still paying hefty bills for underutilized virtual machines or physical servers?
Time to escape. No, not a Sci-Fi thriller — we're talking about containerization.
What You’ll Learn in This Blog:
What is a container?
Why are containers better than virtual machines (VMs)?
Introduction to Docker
Docker architecture and lifecycle
Writing your first Dockerfile
Running your first Docker container
Let’s dive in.
Before Containers: The Virtual Machine Era
We all know about physical servers — costly, limited, and often underutilized. To optimize usage, virtual machines (VMs) were introduced through hypervisors.
Hypervisors allow multiple VMs to run on a single physical server.
Each VM carries its own OS, libraries, and dependencies.
But guess what? Even VMs don’t always use resources efficiently.
Enter Containers: The Lightweight Heroes
Unlike VMs, containers:
Share the same OS kernel
Are lightweight and fast
Package your application with its libraries and system dependencies
Think of a container as a zip file that includes:
✅ Your app code
✅ Required libraries
✅ System-level dependencies
✅ All wrapped in an isolated environment
You no longer need to install Java, Python, or dependencies on the VM. Just use a base image, build your own, and go.
What is Docker?
Docker is the most widely-used containerization platform.
It allows you to:
Build container images from a
DockerfileRun containers
Share images via registries like DockerHub
Docker Architecture Overview:

Docker CLI – Where you type commands
Docker Daemon – Runs in the background and executes commands
Dockerfile – Describes how to build the image
Image – Read-only blueprint of your app
Container – Live instance of the image
Registry – Stores images (DockerHub, GitHub Container Registry, etc.)
Docker Lifecycle:

Write a
DockerfileBuild an image:
docker build -t your-image-name .Run a container:
docker run your-image-namePush/Pull from registry if needed
Hands-on: Your First Java App with Docker
Step 1: Project Structure
/docker-project
├── Main.java
└── Dockerfile
Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello from Docker!");
}
}
Dockerfile
# Use a base image with Java
FROM openjdk:17-slim
# Set working directory inside container
WORKDIR /app
# Copy source file into container
COPY Main.java .
# Compile Java code
RUN javac Main.java
# Command to run the app
CMD ["java", "Main"]
Run Locally or on EC2
Local Setup:
Install Docker Desktop
Start the Docker engine
Open terminal and:
cd docker-project docker build -t my-java-app . docker run my-java-app
On EC2:
Connect to EC2
Install Docker:
sudo apt update sudo apt install docker.io -y sudo systemctl start docker sudo usermod -aG docker $USERClone your GitHub repo:
git clone https://github.com/your-username/docker-project cd docker-projectBuild and run:
docker build -t my-java-app . docker run my-java-app
Output
Hello from Docker!
You’ve successfully containerized your first Java application!
Conclusion
Containers are the future — faster, lighter, and more efficient than VMs. Docker helps you bring your applications to life in a clean, repeatable environment.
If you're still paying for unused VM resources, maybe it's time to containerize your way out.




