Container
A container is an isolated process on a shared Linux kernel, restricted by namespaces and cgroups and started from an image. It gives an application its own filesystem, network, and process view without booting a separate operating system.
What a container is
A container is a normal Linux process that the kernel presents with a private view of the system: its own filesystem, network interfaces, process tree starting at PID 1, hostname, and mounts. Namespaces control what the process can see. Control groups (cgroups) control how much CPU, memory, and I/O it can use. Because no second kernel boots, containers start in well under a second.
Namespaces Docker uses
- PID: the container sees its app as PID 1, while the host sees a normal PID.
- NET: separate interfaces, routing table, and ports.
- MNT: its own mounts and root filesystem.
- UTS: its own hostname.
- IPC: isolated shared memory and message queues.
- Cgroup: its own view of the cgroup tree.
- User: maps container UIDs to different host UIDs, available through user namespace remapping and rootless mode but not enabled by default.
Limits with cgroups
docker run -d --name payment-api --memory=512m --cpus=1.5 payment-api:v3.1.0docker inspect payment-api --format '{{.HostConfig.Memory}}'# 536870912# If it exceeds the limit the kernel kills it: exit code 137, OOMKilled truedocker inspect payment-api --format '{{.State.OOMKilled}}'Image versus container
An image is the read-only template, and a container is a running instance with its own thin writable layer. Many containers can start from one image and share its layers on disk.
Useful commands
docker run -it --rm ubuntu:24.04 bash # interactive throwaway containerdocker ps -a # running and stopped containersdocker logs payment-api # why did it exitdocker exec -it payment-api sh # shell in a running containerRememberContainers share the host kernel, so a kernel vulnerability can affect every container on that host.
SecurityAvoid
--privileged. If a container needs one extra permission, add only that capability with--cap-add.
Frequently Asked Questions
How is a container different from a virtual machine?
A VM runs a full guest operating system with its own kernel on emulated hardware. A container is a process on the host kernel with isolated views and resource limits, so it starts faster and uses less memory but offers weaker isolation.
Is a container a security boundary like a VM?
Not by itself. All containers on a host share one kernel, so kernel bugs or dangerous settings like --privileged can lead to escapes. For untrusted workloads, add sandboxes such as gVisor or Kata Containers.
Why is my data gone after the container was removed?
Files written to the container filesystem live in its writable layer, which is deleted with the container. Use a volume for data that must persist.