A Docker Container in Plain Words
In plain words, a Docker container is an app running on Linux with an isolated view of the system, started from a packaged image.
The Docker documentation calls containers isolated processes for each part of your app. A container is not a tiny computer. It is a process, or a small group of processes, that the Linux kernel isolates with two built in features: namespaces, which control what a process can see, and control groups (cgroups), which can limit what it uses.
Isolation is the default, not a guarantee. A container normally gets its own process and network namespaces, but it can be given host folders or share namespaces with the host when it is started that way, as the security section shows.
Docker released its engine as open source in 2013. The Open Container Initiative (OCI) was launched on June 22, 2015 by Docker, CoreOS and others, and Docker contributed its container format and the runc runtime to it. The OCI now maintains the image, runtime and distribution specifications, so images built with Docker can be used by other compatible tools, including Podman and higher level tools built on containerd.
| Term | What it is | Example from the tests below |
|---|---|---|
| Image | Read only layers of files plus settings such as the start command | nginx:1.29-alpine, 8 layers, 26.9 MB content size |
| Container | One instance of an image, a process tree with a private view of the system | web, running nginx on port 80 inside |
| Docker Engine | dockerd serves the Docker API, containerd manages container lifecycles and runc, an OCI runtime, does the low level setup | Engine 29.9.3, containerd 2.4.2, runc 1.5.2 |
| Registry | A server that stores images for download | Docker Hub, where docker pull fetched nginx |
The layer count and sizes in that table come from these two commands. The content size is the compressed image data, and the disk usage is what the unpacked image takes on this host, so the two numbers measure different things.
docker image inspect nginx:1.29-alpine --format 'Layers={{len .RootFS.Layers}} Arch={{.Architecture}}'
docker image ls nginx:1.29-alpineLayers=8 Arch=amd64
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
nginx:1.29-alpine 5616878291a2 93.5MB 26.9MB UContainer vs Image vs Virtual Machine
A container vs an image is an instance vs its read only template, while a virtual machine adds a whole guest kernel.
The layers below show where each one sits on a server. Read each column from the top down to the hardware.
| Layer | Image | Container | Virtual machine |
|---|---|---|---|
| Your app | Stored as files in a layer | Running as an isolated process | Running inside the guest OS |
| Libraries and userland | Read only layers, for example Alpine | The same read only layers plus one writable layer | A full guest OS install |
| Kernel | None, an image has no kernel | The host kernel, shared | Its own guest kernel |
| Isolation done by | Nothing, it is just files | Namespaces, cgroups and other kernel controls | A hypervisor and virtual hardware |
| Storage | Image layers | Image layers plus its writable data | A guest OS disk plus app data |
| Start | Does not run | One docker run --rm nginx:1.29-alpine true took 0.31 seconds here | Boots a full OS first, so usually slower |
One image can start many containers. Each container reads the shared image layers and writes only to its own thin layer, so ten containers from one image do not need ten copies of the image on disk.
Containers and VMs are not rivals in practice. Your VPS is already a VM, and putting Docker on top of it is a popular way to run containers. The VM gives you your own kernel, and the containers split your apps inside it.
Run Your First Docker Container
To run your first Docker container you need Docker Engine on Linux, then one docker run command that names an image.
Installing Docker Engine on Ubuntu from the official Docker repository is covered step by step in our guide to installing Docker and self hosting n8n with Docker Compose, so this page starts with Docker installed. First check that the client can reach the daemon.
docker version --format '{{.Server.Version}}'29.9.3The smallest test is the hello-world image. Docker downloads it, creates a container, runs it and prints a message. The output below is trimmed to its first lines.
docker run --rm hello-worldUnable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.Start a Web Server in a Container
A web server in a container shows every part at once: a background process, a published port and resource limits.
docker run -d --name web -p 127.0.0.1:18080:80 --memory 256m --cpus 0.5 nginx:1.29-alpinebe97b4cbd8b84b8451a874f4fde61481d86d3c5ec99f0f87ff7366aecb3ff026The long string is the container ID. Here is what each option did.
| Option | Meaning |
|---|---|
-d | Run in the background and print the container ID |
--name web | Give the container a name to use instead of the ID |
-p 127.0.0.1:18080:80 | Forward port 18080 on the host loopback address to port 80 in the container, host side first |
--memory 256m | Cap the memory charged to the container |
--cpus 0.5 | Limit it to the CPU time of half a CPU, spread over any cores, without reserving a core |
nginx:1.29-alpine | The image name and tag to start from |
Binding to 127.0.0.1 keeps the port private to the host, which suits a service behind a reverse proxy. Publishing a public port is shown in the VPS section. Now confirm the container is up and answering.
docker ps --filter name=^web$
curl -sI http://127.0.0.1:18080 | head -3CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be97b4cbd8b8 nginx:1.29-alpine "/docker-entrypoint.…" 53 seconds ago Up 52 seconds 127.0.0.1:18080->80/tcp web
HTTP/1.1 200 OK
Server: nginx/1.29.8
Date: Thu, 03 Dec 2026 09:59:00 GMTUp in the STATUS column and a 200 OK reply mean the process runs and the port mapping works on the host. They do not prove the service is reachable from the internet, which also depends on the bind address and the firewalls in between.
How Docker Container Isolation Works
Docker container isolation comes mainly from Linux namespaces, which give a process its own private view of one part of the system.
The Linux manual lists eight namespace types. Comparing the namespace IDs of a shell on the host with the nginx process of the web container shows which ones Docker separated in this test.
P=$(docker inspect -f '{{.State.Pid}}' web)
for n in pid net mnt uts ipc user cgroup time; do
printf "%-6s host %-24s container %s\n" $n $(readlink /proc/$$/ns/$n) $(readlink /proc/$P/ns/$n)
donepid host pid:[4026531836] container pid:[4026532267]
net host net:[4026531833] container net:[4026532268]
mnt host mnt:[4026531832] container mnt:[4026532264]
uts host uts:[4026531838] container uts:[4026532265]
ipc host ipc:[4026531839] container ipc:[4026532266]
user host user:[4026531837] container user:[4026531837]
cgroup host cgroup:[4026531835] container cgroup:[4026531835]
time host time:[4026531834] container time:[4026532317]A different number means the container has its own namespace of that type. PID, network, mount, UTS, IPC and time differ here. User and cgroup are shared with the host. The cgroup result is expected on this host, because Docker defaults to a private cgroup namespace on cgroup v2 and to the host one on cgroup v1. The time namespace only covers boot and monotonic clocks, so the wall clock still comes from the host.
These are the defaults observed in this test. Options such as --network host, --pid host and --ipc host make a container share that namespace with the host instead.
| Namespace | What the container gets | Evidence below |
|---|---|---|
| PID | Its own process numbers, with its main process as PID 1 | ps inside shows nginx as PID 1, its workers and the ps command itself |
| Network | Its own interfaces, addresses and ports | Only lo and eth0 inside, versus the host interface list |
| Mount | Its own root filesystem built from the image | /etc/os-release says Alpine inside and Ubuntu on the host |
| UTS | Its own hostname | be97b4cbd8b8 inside, vm on the host |
| IPC | Its own shared memory and message queues | A separate namespace ID |
| User | Not separate by default, so UIDs match the host | UID 101 inside is UID 101 outside |
| Cgroup | Shared with the host on this cgroup v1 setup, private by default on cgroup v2 | The same namespace ID on both sides |
| Time | Its own boot and monotonic clocks, while wall clock time stays shared | Different namespace IDs |
What the Container Sees From the Inside
From the inside, the container sees its own hostname, its own interfaces and the files of its image instead of the host.
docker exec web hostname; hostname
docker exec web ip -o link | cut -d' ' -f2
docker exec web head -2 /etc/os-release; head -2 /etc/os-releasebe97b4cbd8b8
vm
lo:
eth0@if26:
NAME="Alpine Linux"
ID=alpine
PRETTY_NAME="Ubuntu 24.04.5 LTS"
NAME="Ubuntu"The host list from ip -o link on the same machine also showed eth0, the Docker bridge and a veth interface, the host end of the cable whose other end is the eth0 inside the container.
Processes Inside and Outside the Container
Processes inside the container see only their own PID namespace, so the nginx master process is PID 1 there.
docker exec web psPID USER TIME COMMAND
1 root 0:00 nginx: master process nginx -g daemon off;
20 nginx 0:00 nginx: worker process
21 nginx 0:00 nginx: worker process
47 root 0:00 psPID 1 is simply the main process named in the image or in docker run. From the host the same processes are ordinary entries in the process table with host PIDs, which is the clearest proof that a container is a process and not a machine.
docker top webUID PID PPID C STIME TTY TIME CMD
root 6732 6707 0 14:58 ? 00:00:00 nginx: master process nginx -g daemon off;
redis 6780 6732 0 14:58 ? 00:00:00 nginx: worker process
redis 6781 6732 0 14:58 ? 00:00:00 nginx: worker processThe Shared Kernel and Shared User IDs
The shared kernel is visible with one command, because uname -r prints the same kernel release inside and outside.
docker exec web uname -r
uname -r6.18.44-fc-v1157
6.18.44-fc-v1157The container ships Alpine files but runs on the Ubuntu host kernel. That is why a Linux container needs a Linux kernel underneath, and why a kernel flaw can affect every container on the host.
The docker top output also shows the nginx workers as redis on the host. Inside, they run as nginx with UID 101. On this host UID 101 belongs to the redis account, and with no user namespace the kernel only sees the number.
docker exec web id nginx
id redisuid=101(nginx) gid=101(nginx) groups=101(nginx),101(nginx)
uid=101(redis) gid=103(redis) groups=103(redis)Likewise, the root user inside an ordinary container shows up to the host kernel as user number 0. Namespaces, a reduced set of capabilities, seccomp and any AppArmor or SELinux policy restrict it, but it is not the same as an unprivileged host user.
Two Docker features change that. User namespace remapping maps container UIDs to unprivileged host UIDs while the daemon still runs as root. Rootless mode moves the daemon and every container it starts under a regular, unprivileged account. Neither is on by default.
How Cgroups Limit a Docker Container
Cgroups limit a Docker container by capping how much CPU time, memory and how many processes the kernel lets it use.
Without explicit limit options Docker sets no per container CPU or memory cap, so a container can use as much as the host scheduler allows. Limits set on the host or a parent cgroup can still apply. The web container was started with --memory 256m --cpus 0.5, and docker inspect shows both settings.
docker inspect web --format 'NanoCPUs={{.HostConfig.NanoCpus}} Memory={{.HostConfig.Memory}}'NanoCPUs=500000000 Memory=268435456500000000 nano CPUs is half a CPU and 268435456 bytes is 256 MiB. docker stats shows live use against the memory limit, and its CPU column shows usage, not the quota.
docker stats --no-stream webCONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
be97b4cbd8b8 web 0.00% 3.547MiB / 256MiB 1.39% 966B / 126B 0B / 0B 3Check Which Cgroup Version Your Host Uses
Your cgroup version decides where limits live, and Docker documents Ubuntu as using cgroup v2 by default since 21.10.
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then echo "cgroup v2"; else echo "cgroup v1"; ficgroup v1This test VM printed v1 because its boot setup mounts the v1 controllers, with no cgroup option on the kernel command line. A standard Ubuntu 24.04 server prints v2. The Docker commands on this page work the same on both, but the files under /sys/fs/cgroup have different names, so prefer docker inspect and docker stats when you check limits. Docker Engine 29 deprecates cgroup v1, with support promised until at least May 2029, so this test uses it only to document what was observed. Use cgroup v2 for new deployments.
What Happens When a Container Runs Out of Memory
When a container runs out of memory the kernel kills a process inside it, and Docker records that as an OOM kill.
This test gives a container 32 MB and pipes 100 MiB of zero bytes through BusyBox tail. The stream has no newline, so tail must keep the whole unfinished last line in memory, and its buffer grows past the limit. The host had no swap.
docker run --name hog --memory 32m nginx:1.29-alpine sh -c 'head -c 100m /dev/zero | tail > /dev/null'; echo "exit=$?"
docker inspect -f 'OOMKilled={{.State.OOMKilled}} ExitCode={{.State.ExitCode}}' hogKilled
Killed
exit=137
OOMKilled=true ExitCode=137Exit code 137 means the process got signal 9 (128 plus 9), and OOMKilled=true confirms the memory limit caused it. The other containers kept running. A memory limit restricts the memory charged to one container, but it does not isolate the container from every host problem, such as a full disk or a busy CPU without a limit.
Docker Container Data and the Writable Layer
Docker container data in the writable layer is deleted with the container, so data you need belongs in a named volume or a bind mount.
Every container gets a thin writable layer over the read only image. docker diff lists what changed there, with A for added and C for changed. Here a file was written into the web root of a test container.
docker exec web sh -c 'echo "hello" > /usr/share/nginx/html/note.txt'
docker diff web | grep htmlC /usr/share/nginx/html
A /usr/share/nginx/html/note.txtRemove the container and start a new one from the same image, and the file is gone, because the new container gets a fresh writable layer.
docker rm -f web
docker run -d --name web -p 127.0.0.1:18080:80 nginx:1.29-alpine
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:18080/note.txt404Keep Data With a Docker Volume
A Docker volume keeps data outside the container, so it survives when the container is removed and recreated.
docker volume create site
docker run -d --name web -p 127.0.0.1:18080:80 -v site:/usr/share/nginx/html nginx:1.29-alpine
docker exec web sh -c 'echo "kept" > /usr/share/nginx/html/note.txt'
docker rm -f web
docker run -d --name web -p 127.0.0.1:18080:80 -v site:/usr/share/nginx/html nginx:1.29-alpine
curl -s http://127.0.0.1:18080/note.txtkept| Storage | Lives in | Survives docker rm | Use it for |
|---|---|---|---|
| Writable layer | The container itself | No | Temporary files and caches |
| Named volume | Storage managed by Docker | Yes | Databases, uploads, app data |
| Bind mount | A host folder you choose | Yes, it is on the host | Config files and code you edit on the host |
| tmpfs mount | Host memory | No, lost when the container stops | Scratch data that should not be written to disk |
The Docker Container Lifecycle
The Docker container lifecycle runs from created to running, paused, exited and removed, and docker ps -a shows the current state.
Each command below moved a test container named demo to the next state, read after each step with docker ps -a --filter name=^demo$. The restarting row comes from a second container that exits with an error under a restart policy.
| Command | State | Status shown | What is true now |
|---|---|---|---|
docker create --name demo nginx:1.29-alpine | created | Created | Writable layer exists, no process yet |
docker start demo | running | Up Less than a second | The main process runs |
docker pause demo | paused | Up Less than a second (Paused) | Processes frozen but still in memory |
docker unpause demo then docker stop demo | exited | Exited (0) Less than a second ago | Process ended, writable layer kept |
docker rm demo | none | No row returned | Container and its writable layer deleted |
docker run -d --name flaky --restart on-failure nginx:1.29-alpine sh -c 'sleep 1; exit 3' | restarting | Restarting (3) Less than a second ago | Docker is starting it again after a failed exit |
The flaky container showed RestartCount=4 a few seconds later. Docker also has removing and dead states, which you rarely see for long.
An exited container keeps its writable layer until you remove it, which is how stopped containers quietly fill a disk. docker ps -a lists them, and docker container prune removes all stopped containers after asking you to confirm. A container also stops by itself when its main process ends, so one whose program exits at once shows as Exited right after docker run.
How Secure Is a Docker Container
A Docker container is a useful security boundary for your own trusted apps, but it is weaker than a virtual machine.
Docker drops most Linux capabilities by default, and namespaces hide other processes, which stops many mistakes and simple attacks. The kernel is still shared, so a kernel flaw or a badly configured container can reach the host. These settings make the biggest difference.
| Setting | Effect | What it does not do |
|---|---|---|
--user 101:101 or USER in the image | The app runs as a non root UID | It is still that same UID on the host without a user namespace |
--cap-drop ALL then add back only what is needed | Removes privileged kernel operations | Does not stop the app reading files it can already reach |
--read-only | Makes the container root filesystem read only | Does not protect mounted volumes |
| User namespace remapping or rootless mode | Container root maps to an unprivileged host user | Off by default, and some images need changes |
--privileged or --pid host | Grants extensive privileges and device access, or exposes the host process list | Removes much of the isolation, so avoid it |
Membership of the docker group | Lets a user control the daemon | Docker warns it grants root level privileges |
The first three settings were tested together. The process ran as UID 101 and could not write to the image files.
docker run --rm --user 101:101 --read-only --cap-drop ALL nginx:1.29-alpine sh -c 'id; touch /etc/x'touch: /etc/x: Read-only file system
uid=101(nginx) gid=101(nginx) groups=101(nginx)A refused write proves the root filesystem is read only. It does not prove the container is safe, which also depends on updated images, a patched host kernel and what you mount or publish.
When Not to Use a Docker Container
Skip a Docker container when the workload needs its own kernel, strong isolation from untrusted users or a full desktop.
| Situation | Better fit | Why |
|---|---|---|
| Web apps, APIs, databases and self hosted tools on one server | Container | Quick to start and update, easy to move with the image |
| The same app in development and production | Container | The image pins the libraries and versions |
| Code from users you do not trust | Virtual machine or a sandboxed runtime | A shared kernel is a weaker boundary |
| A custom kernel, kernel modules or a different OS | Virtual machine | Containers cannot bring their own kernel |
| Windows apps on a Linux host | Virtual machine | Windows images need a Windows kernel |
| A full graphical desktop for daily work | Virtual machine | Containers suit application workloads better than complete desktops |
| A single program that already installs cleanly | Either | A container adds a layer to learn and maintain |
On Windows the rules differ. Microsoft documents two modes for Windows containers: process isolation, which shares the host kernel like Linux containers, and Hyper-V isolation, which runs each container in a small VM with its own kernel. On macOS, Docker Desktop runs Linux containers in a Linux virtual machine, because macOS has no Linux kernel to share.
Running Docker Containers on a VPS
Running Docker containers on a VPS gives them a guest Linux kernel to share, inside a virtual machine where you manage the OS.
That combines both models in this guide. The VPS supplies the VM boundary, and containers split your apps inside it. Two worked examples on this blog show the pattern end to end: running Jellyfin on a VPS and the n8n guide linked above.
Publish a Port to the Internet
To publish a port to the internet, leave the host address out of -p, and Docker listens on every host address.
docker run -d --name web-public -p 8080:80 nginx:1.29-alpine
docker port web-public
ss -ltnH '( sport = :8080 )' | awk '{print $4}'80/tcp -> 0.0.0.0:8080
0.0.0.0:8080Here it listened on every IPv4 address. Docker documents that a port published this way goes to all host addresses, 0.0.0.0 and [::], so check IPv6 on your own server with ss -ltn too. This test host has no IPv6 setup, which is why no [::] line appears. Then open http://203.0.113.10:8080 from another machine. That address is a documentation example, so use your server IP.
Where Docker Compose Fits
Docker Compose fits once an app needs several containers, such as an app, a database and a cache, managed together from one file.
Kubernetes goes further and schedules Pods, which hold one or more containers, across a cluster of servers. For one VPS, plain Docker or Compose is usually enough. Before you go live, check these points.
| Check | Command or setting |
|---|---|
| Pin a version tag, and the digest where repeat deployments must match | nginx:1.29-alpine, or the full digest shown below |
| Keep app data in volumes and back them up | -v name:/path |
| Set memory and CPU limits | --memory and --cpus |
| Restart after a crash or reboot | --restart unless-stopped |
| Publish only the ports you need | -p 127.0.0.1:port:port behind a reverse proxy |
| Update images and the host | docker pull, then recreate the containers, plus apt upgrade and a reboot when a new kernel needs one |
A tag like 1.29-alpine can move to a newer build, while a digest always names the same image. This prints the digest of the exact image tested here.
docker image inspect --format '{{index .RepoDigests 0}}' nginx:1.29-alpinenginx@sha256:5616878291a2eed594aee8db4dade5878cf7edcb475e59193904b198d9b830dePut that full value in place of nginx:1.29-alpine in a docker run command to pin the same image index, and Docker selects the matching platform image for the host. If you want a server ready for this, a Docker VPS gives you full root access on KVM, so you manage the guest OS, its firewall and your containers.
Docker Container Problems and Fixes
Most Docker container problems show up in docker ps -a, docker logs or docker inspect, so start with those three.
docker logs CONTAINER_NAME
docker inspect -f '{{.State.Status}} {{.State.ExitCode}} {{.State.OOMKilled}}' CONTAINER_NAME| What you see | Likely cause | Fix |
|---|---|---|
Exited right after docker run | The main process finished or crashed | Read docker logs for that container and check its command |
| Exited (137) with OOMKilled true | Memory limit reached | Raise --memory or lower the app memory use |
| Port is already allocated | Another container or program holds the host port | Pick another host port in -p |
| Data gone after an update | Data was in the writable layer | Move it to a named volume or bind mount |
| exec format error | The executable does not match the host, often a different CPU architecture | Compare the image architecture with uname -m and pull or build for your platform |
| Permission denied on a mounted folder | Ownership, mode, groups or a security policy do not allow that UID | Check folder ownership and mode, the container UID and GID, any user namespace mapping and SELinux labels |
Questions people ask
What is a Docker container in simple terms?
It is an app running with an isolated view of the system, with its own processes and usually its own network, on the shared Linux kernel.
What is the difference between a Docker image and a container?
The image is a fixed blueprint. A container is a copy started from it that gets a private layer for any changes.
Is a Docker container a virtual machine?
No. A container is an isolated process on the host kernel, while a virtual machine boots its own operating system and kernel.
Do Docker containers share the host operating system?
They share the host kernel but bring their own files. In the test an Alpine container ran on the Ubuntu host kernel.
Can multiple Docker containers run on one server?
Yes. Each gets its own writable layer and normally its own process, mount and network namespaces. They share the kernel and image layers and compete for host resources within any limits you set.
What happens to data when a Docker container is deleted?
Data in the writable layer is deleted with it. Data in a named volume or a bind mount stays.
Can Docker containers run on Windows and Mac?
On Windows and macOS, Docker Desktop hosts Linux containers inside a small Linux VM it manages. Windows containers need a supported Windows host and do not run on macOS.
Are Docker containers secure?
They are a useful but weaker boundary than a VM. Run as non root, drop capabilities, avoid privileged mode and keep images updated.
Sources
- Docker Docs, What is a container
- Open Container Initiative, About the OCI
- Linux manual page, namespaces(7)
- Docker Docs, Resource constraints
- Docker Docs, Runtime metrics and cgroup versions
- Docker Docs, Storage
- Docker Docs, Port publishing and mapping
- Docker Docs, Docker Engine security
- Microsoft Learn, Isolation modes for Windows containers