🐳 Getting Started with Docker: Images, Containers & Dockerfile Basics (2025)

πŸ“Œ What is Docker?

Docker is an open-source platform that lets you package your applications and dependencies into a standardized unit called a container. Containers are lightweight, fast, and portable β€” like mini virtual machines, but without the heavy baggage.

Think of Docker containers as isolated sandboxes where your app always behaves the same β€” no more β€œworks on my machine” drama!

πŸ†š Docker vs Virtual Machines

Aspect Docker Virtual Machines
Startup Time ⚑ Milliseconds ⏳ Minutes
Resource Usage πŸ’‘ Low πŸ”‹ High
Isolation Level Medium (OS shared) High (Own OS)

βš™οΈ Components of Docker

πŸ§ͺ Running Your First Docker Container

Let's run the classic Hello World container:

docker run hello-world

This pulls the hello-world image from Docker Hub and runs it as a container. You should see:

Hello from Docker!
This message shows that your installation appears to be working correctly.

πŸ“¦ Dockerfile: Building Your Own Image

Let's say you have a simple Node.js app. Here's how you can write a Dockerfile:

# Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]

To build this image:

docker build -t my-node-app .

To run the container:

docker run -p 3000:3000 my-node-app

🐍 Python Version (Bonus)

If you prefer Python, here's a minimal Flask app app.py and Dockerfile:

# app.py
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello from Docker!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)
# Dockerfile
FROM python:3.11-alpine
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]

🧱 Image & Container Lifecycle

πŸ” Pulling Images from Docker Hub

Docker Hub is like GitHub for containers. To pull a ready-to-use image:

docker pull nginx
docker pull mongo
docker pull python:3.11

Then run them like this:

docker run -d -p 8080:80 nginx

🧠 Pro Tips for Beginners

🎯 Summary

You've just walked through the basics of Docker β€” from containers and images to building your first Dockerfile. Whether you're building in Node.js or Python, Docker keeps your environment clean and consistent.

In our next post, we'll dive into πŸ”— (Post 2): Docker Volumes & Networks: Managing Data & Communication!

β€” Blog by Aelify (ML2AI.com)

πŸ“š Documentation Index