AtomLearnAtomLearn
DashboardGoalsPathAchievementsReviewSign In
Docker & ContainersNot Started

Docker Basics

Containers vs VMs, images, and core Docker commands (run, ps, stop, rm)

0%
Knowledge0%
Learn & Drill
Fluency0%
Drill & Speed
Retention0%
Mastery & Review
Confidence0%
All modes
Practice
Knowledge
Fluency
Retention

Knowledge Debt detected

You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.

Explanation

Docker packages your app and everything it needs (code, runtime, libraries, config) into a container — a portable, isolated process that runs the same everywhere.

Container vs Virtual Machine:

| | Container | Virtual Machine | |---|---|---| | What it includes | App + runtime + libs | Entire OS + app | | Startup time | ~milliseconds | ~minutes | | Disk size | ~MB | ~GB | | Isolation | Process-level (shared kernel) | Full OS isolation | | Use case | Microservices, CI/CD | Strong isolation needed |

Containers share the host OS kernel — they're not VMs. This makes them fast and lightweight.

Images vs Containers:

  • Image — a read-only template (like a class). Stored on disk, versioned with tags.
  • Container — a running instance of an image (like an object). Has its own writable layer.

Essential commands:

bash # Pull an image from Docker Hub docker pull python:3.12-slim # Run a container docker run python:3.12-slim python --version # -d: detached (background) -p: port map --name: friendly name docker run -d -p 8080:80 --name webserver nginx # List running containers docker ps docker ps -a # include stopped containers # Stop and remove docker stop webserver docker rm webserver docker stop $(docker ps -q) # stop all running containers # List images docker images # Remove an image docker rmi nginx

Running interactively:

bash # Start a bash shell inside a container docker run -it python:3.12-slim bash # Exec into a running container docker exec -it webserver bash

Port mapping-p host_port:container_port: ``bash docker run -d -p 3000:80 nginx # Requests to localhost:3000 → forwarded to port 80 inside the container

Volumes — persisting data:

bash # Bind mount: maps a host directory into the container docker run -v /host/data:/app/data myapp # Named volume: Docker manages the storage location docker run -v mydata:/app/data myapp docker volume ls `` Without a volume, data written inside a container is lost when the container is removed.

Examples

Running your first container

`-d` runs in background; `-p 8080:80` maps host port 8080 to container port 80; `--name` gives a friendly reference

# Pull and run a Python container
docker pull python:3.12-slim

# Run a one-off command (container exits immediately after)
docker run python:3.12-slim python -c "print('Hello from Docker!')"

# Run a web server in the background
docker run -d --name myapp -p 8080:80 nginx
# curl localhost:8080 → nginx welcome page

# Check it's running
docker ps
# CONTAINER ID   IMAGE   STATUS    PORTS                  NAMES
# a1b2c3d4e5f6   nginx   Up 3 s    0.0.0.0:8080->80/tcp   myapp

# View logs
docker logs myapp

# Stop and clean up
docker stop myapp
docker rm myapp

Working with images and cleanup

`docker system prune` is the fastest way to reclaim disk space on a dev machine — be cautious on shared environments

# List all local images
docker images
# REPOSITORY       TAG          SIZE
# python           3.12-slim    131MB
# nginx            latest       187MB

# Remove a specific image
docker rmi nginx

# See all containers (including stopped)
docker ps -a

# Remove a stopped container
docker rm container_id_or_name

# One-liner cleanup: remove all stopped containers
docker container prune

# Remove all unused images, containers, networks
docker system prune -a

How well did you understand this?

Next in Docker & Containers

Writing Dockerfiles

Continue