📝 Docker

What Is Docker and Why You Need It

P
Author
Pyland
📅
Published
08.05.2026
⏱️
Reading time
2 min
👁️
Views
119
🌱
Level
Beginner

Docker solves one of the most common problems in software development: “It works on my machine, but not on the server.”

The Root of the Problem

When you run code locally, it runs in a specific environment: a particular Python version, specific libraries, a specific OS. The server has a different Python version, different package versions, a different OS. The code breaks even if you didn’t touch it.

Classic scenario: you wrote an app on Python 3.11, your colleague has Python 3.9, CI uses 3.10, production runs 3.8. match doesn’t work somewhere, a package is missing somewhere else, systemd blocks a port somewhere. Every environment is its own source of surprises.

What Is Docker

Docker is a tool for running applications in containers. A container holds everything it needs: code, runtime, libraries, system dependencies. The same package runs identically everywhere — on your Mac, your colleague’s server, and in the cloud.

Analogy: a shipping container. Everything is packed inside. Ship it by sea, rail, or truck — the contents don’t change.

Image vs Container

  • Image — an immutable template. Like a class in OOP or an installation disk.
  • Container — a running instance of an image. Like an object instantiated from a class.

One image → many containers. Delete a container — the image stays.

Container vs Virtual Machine

Virtual Machine Docker Container
What it isolates An entire computer (kernel, memory, disk) Only processes
Size Gigabytes Megabytes
Startup time Minutes Seconds
Uses host kernel No Yes

A container doesn’t emulate hardware — it uses the host kernel and isolates only processes. That’s why it’s faster and lighter.

In short:
- A VM runs a full OS with its own kernel — maximum isolation, but costs gigabytes of RAM and minutes to start
- Docker uses the host kernel and isolates only the process space — lightweight, fast, sufficient for most tasks
- VMs are needed when you require a different OS (a Windows container on a Linux host); Docker is for isolating an application

Docker vs virtualenv

virtualenv only isolates Python libraries. Docker isolates everything: the Python version, system packages, ports, the filesystem. Docker works with more than just Python.

A Simple Dockerfile

Dockerfile is a text file with instructions for building an image:

# Use the official Python image
FROM python:3.11-slim

# Working directory inside the container
WORKDIR /app

# Copy dependencies and install them
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy all source code
COPY . .

# Command to start the application
CMD ["python", "app.py"]

Build the image and run a container:

# Build the image tagged as myapp
docker build -t myapp .

# Run the container, forwarding host port 8000 → container port 8000
docker run -p 8000:8000 myapp

The -p 8000:8000 flag means: traffic on port 8000 of your machine is forwarded to port 8000 of the container. Without this flag the application runs but is unreachable from outside the container.

Real-World Scenario

You’re developing a Django application. Without Docker:

  1. A new developer clones the repo
  2. Installs Python (possibly the wrong version)
  3. Creates a virtualenv, installs dependencies
  4. Installs PostgreSQL, configures user and database
  5. Sets environment variables
  6. Something goes wrong somewhere between steps 3–4

With Docker:

git clone https://github.com/example/myapp
docker compose up

Done. The same Python version, the same PostgreSQL, the same variables — for everyone on the team.

What Docker Gives a Developer

  • A consistent environment across the whole team
  • Instant startup of databases and services
  • Safe experimentation — break a container, delete it, spin up a new one
  • Simple deploys: build the image, ship it, run it
  • New team member onboarding comes down to a single command

Your reaction to the article

💬 Comments (0)

🔐 Sign in to leave a comment
🚪 Login
💭

No comments yet

Be the first to share your opinion about this article!

🔗 Similar

Similar articles

Continue learning with these materials

📝

What is an ORM

ORM (Object-Relational Mapping) is a technology that lets you work with a database through Python...

📅 30.06.2026 👁️ 135
📝

AI Agents: ReAct Loop and Autonomous Actions

A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and...

📅 30.06.2026 👁️ 111
📝

Pydantic v2: Data Validation in Python

Pydantic is a library for data validation using type annotations. Version 2 was rewritten in...

📅 30.06.2026 👁️ 109

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!