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!
| Aspect | Docker | Virtual Machines |
|---|---|---|
| Startup Time | β‘ Milliseconds | β³ Minutes |
| Resource Usage | π‘ Low | π High |
| Isolation Level | Medium (OS shared) | High (Own OS) |
docker run).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.
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
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"]
docker build -t name .docker run -d -p host:container namedocker psdocker stop CONTAINER_IDdocker rm CONTAINER_IDdocker rmi IMAGE_IDDocker 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
docker ps -a to see all containers (even stopped).--rm to auto-remove containers after they stop..dockerignore (like .gitignore) to skip files during build.docker build -t myapp:v1 .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