Containers and Docker Basics
Learn what a container really is, how it differs from a VM, and how to run, inspect and manage containers with Docker.
Beginner · about 8 hours · difficulty 2/5
Learn first: Processes, Signals and Resources, How the Internet Works: TCP/IP and the OSI Model
A container is a normal Linux process isolated with kernel features: namespaces (its own view of PIDs, network, mounts, users) and cgroups (limits on CPU and memory). It is not a tiny VM; it shares the host kernel, which is why it starts in milliseconds.
Key concepts
- An image is a read-only, layered filesystem plus metadata (entrypoint, env, ports). A container is a running instance of an image with a thin writable layer on top.
- OCI standards mean images built with Docker run on containerd, CRI-O, Podman and Kubernetes.
- Docker architecture: the
dockerCLI talks to the daemon, which uses containerd and runc underneath.
Everyday commands
docker run -d -p 8080:80 --name web nginx, docker ps, docker logs -f, docker exec -it web sh, docker inspect, docker stop/rm, docker images, docker system prune.
Data and networking
- Volumes persist data beyond the container; bind mounts map host paths (great for development).
- Bridge networks give containers DNS by name;
hostnetworking skips isolation. - Resource limits:
--memory,--cpus.
Pitfalls
Storing data in the container layer (lost on removal), running as root by default, and treating containers like pets you SSH into and patch.
Good enough to move on: you can explain containers vs VMs, run a multi-container setup on a user-defined network with a volume, and debug a container with logs, exec and inspect.
Key concepts
- Namespaces and cgroups
- Images vs containers
- OCI, containerd and runc
- run, exec, logs, inspect
- Volumes and bind mounts
- Container networking
- Resource limits
- Podman: Daemonless, rootless-friendly alternative CLI
Mini project
Run Postgres with a named volume and a small web app on the same user-defined network, connect them by container name, then delete and recreate the Postgres container and prove the data survived.
Check yourself
Why can a container start in under a second when a VM takes much longer, and what does that imply about kernel sharing?
Free resources
- Docker: Get started (Docker)
- Open Container Initiative (OCI)