LearnFrenzy
Sign in Take a free test

Core Services · Lesson 4 of 6

Containers, Docker and Kubernetes for Beginners

"It works on my machine" stops being an excuse with containers. Learn what a container is, write a Dockerfile, run and push an image, and understand what Kubernetes does — pods, deployments and services — without drowning in YAML.

13 min read Intermediate Updated Nov 9, 2026 Reviewed by Saurabh Samir

You build a Flask app on your laptop with Python 3.12. Your teammate has Python 3.9 and a different version of a library. The server runs another Linux distribution. Each environment behaves slightly differently, and the app breaks in places it never broke for you. Containers fix this by packaging the app together with everything it needs to run.

What is a container?

A container is a lightweight, isolated package containing your application, its runtime, libraries and settings. It runs the same on your laptop, a colleague's machine, a test server and the cloud.

Virtual machineContainer
IncludesA full guest operating systemJust the app and its dependencies; shares the host's kernel
SizeGigabytesOften tens to hundreds of megabytes
Starts inMinutesSeconds or less
IsolationStrongerGood, but lighter

Shipping containers transformed trade because one standard box fits every ship, train and truck. Software containers do the same for applications.

Docker vocabulary

  • Dockerfile — the recipe: start from a base image, copy code, install dependencies, set the start command.
  • Image — the built, read-only package produced from the Dockerfile.
  • Container — a running instance of an image. One image can run as many containers.
  • Registry — where images are stored and shared: Docker Hub, Amazon ECR, Azure Container Registry, Google Artifact Registry.

A real Dockerfile for a Python web app

# Dockerfile
FROM python:3.12-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt   # dependencies first: this layer is cached

COPY . .
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:app"]

Copying requirements.txt before the rest of the code is a deliberate trick: Docker caches each step, so when you change only your code, the slow dependency install is skipped on the next build.

Build, run, push

docker build -t placement-app:1.0 .            # build an image from the Dockerfile
docker run -d -p 8000:8000 placement-app:1.0   # run it; open http://localhost:8000
docker ps                                       # list running containers
docker logs <container-id>                       # see the app's output
docker tag placement-app:1.0 <registry>/placement-app:1.0
docker push <registry>/placement-app:1.0       # share it so a server can pull and run it

Never bake secrets into an image. Passwords and API keys copied into a Dockerfile stay inside the image layers for anyone who pulls it. Pass them at run time as environment variables or through the cloud's secret manager, and add .env to a .dockerignore file.

Docker Compose: several containers together

Most apps need more than one piece — a web app and a database, say. docker compose starts them together from one file:

services:
  web:
    build: .
    ports: ["8000:8000"]
    environment:
      DATABASE_URL: postgresql://app:secret@db:5432/placements
    depends_on: [db]
  db:
    image: postgres:16
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: secret     # fine for local practice only
      POSTGRES_DB: placements
    volumes: ["pgdata:/var/lib/postgresql/data"]
volumes:
  pgdata:

docker compose up and your whole stack is running locally — a big reason Docker is now expected in fresher backend and DevOps roles.

Kubernetes: running containers at scale

Running three containers on a laptop is easy. Running hundreds across many servers — restarting crashed ones, spreading load, rolling out new versions without downtime — needs an orchestrator. Kubernetes (K8s) is the standard one.

  • Cluster — a group of machines (nodes) managed by Kubernetes.
  • Pod — the smallest unit: one (sometimes more) container running together.
  • Deployment — "keep 3 copies of this pod running, and replace them gradually when I ship a new version". If a pod dies, Kubernetes starts a new one.
  • Service — a stable address and load balancing in front of a changing set of pods.
  • Ingress — routes outside HTTP traffic (yourapp.in/api) to the right service.

You describe the desired state ("3 replicas of version 1.4") and Kubernetes keeps working to make reality match it. Managed Kubernetes — Amazon EKS, Azure AKS, Google GKE — runs the control plane for you.

Honest advice: learn Docker well first; it is useful from day one. Kubernetes is powerful but complex — many small apps are better served by simpler container services (AWS App Runner or ECS, Azure Container Apps, Google Cloud Run), covered in the next lesson.

Try it yourself: Install Docker Desktop, write a Dockerfile for any small Python or Node app, build it and run it on port 8000. Then change one line of code, rebuild, and notice which steps were cached. Bonus: add a Postgres container with Docker Compose.

Common interview questions

Try answering each one aloud before you open it.

1What is the difference between a container and a virtual machine?

A VM includes a full guest operating system on a hypervisor; a container packages only the application and its dependencies and shares the host OS kernel. Containers are lighter and start faster; VMs provide stronger isolation.

2What is the difference between a Docker image and a container?

An image is a read-only template built from a Dockerfile. A container is a running instance of that image; many containers can run from the same image.

3What problem does Kubernetes solve?

It orchestrates containers across a cluster: scheduling, scaling, restarting failed containers, service discovery and load balancing, and rolling updates, by continuously matching the running state to a declared desired state.

Practise this

Build something with it

FAQs

Do I need Linux to use Docker?

Docker Desktop runs on Windows and macOS (using a small Linux VM underneath). Basic Linux command-line knowledge still helps a lot when you work inside containers.

Is Kubernetes necessary for freshers?

Docker is commonly expected; Kubernetes is a strong plus for DevOps and cloud roles. Understand the core concepts first — pods, deployments, services — before diving into advanced features.

References & further reading

Finished this lesson?

Mark it complete. Create a free account to save it on every device.

Next lesson

Search LearnFrenzy

Esc

Quick links