Skip to content

Self HostingArticle

What Is a Docker Container and How It Works

  • Updated
  • 12 min read
  • VPS Lane Engineering
Short answer

A Docker container is an isolated process run from an image. It usually sees its own files, processes and network but uses the host kernel.

How we tested this

Every command with output on this page was run on Ubuntu 24.04.5 LTS, x86_64, kernel 6.18, 8 GB RAM with no swap, on a test VM that mounts cgroup v1. Versions were read with dockerd, containerd and runc --version: Docker Engine 29.9.3, containerd 2.4.2 and runc 1.5.2, with the official nginx:1.29-alpine image (nginx 1.29.8 on Alpine 3.23.4) and hello-world. Timings come from a single run and are not a benchmark. No Windows or macOS machine was used, so statements about Docker Desktop and Windows containers follow the documentation linked in the text and under Sources.

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.

Docker terms at a glance
TermWhat it isExample from the tests below
ImageRead only layers of files plus settings such as the start commandnginx:1.29-alpine, 8 layers, 26.9 MB content size
ContainerOne instance of an image, a process tree with a private view of the systemweb, running nginx on port 80 inside
Docker Enginedockerd serves the Docker API, containerd manages container lifecycles and runc, an OCI runtime, does the low level setupEngine 29.9.3, containerd 2.4.2, runc 1.5.2
RegistryA server that stores images for downloadDocker 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.

bash
docker image inspect nginx:1.29-alpine --format 'Layers={{len .RootFS.Layers}} Arch={{.Architecture}}'
docker image ls nginx:1.29-alpine
Output
Layers=8 Arch=amd64
IMAGE               ID             DISK USAGE   CONTENT SIZE   EXTRA
nginx:1.29-alpine   5616878291a2       93.5MB         26.9MB   U

Container 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.

Where an image, a container and a virtual machine sit on one server
LayerImageContainerVirtual machine
Your appStored as files in a layerRunning as an isolated processRunning inside the guest OS
Libraries and userlandRead only layers, for example AlpineThe same read only layers plus one writable layerA full guest OS install
KernelNone, an image has no kernelThe host kernel, sharedIts own guest kernel
Isolation done byNothing, it is just filesNamespaces, cgroups and other kernel controlsA hypervisor and virtual hardware
StorageImage layersImage layers plus its writable dataA guest OS disk plus app data
StartDoes not runOne docker run --rm nginx:1.29-alpine true took 0.31 seconds hereBoots 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.

bash
docker version --format '{{.Server.Version}}'
Output
29.9.3

The 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.

bash
docker run --rm hello-world
Output
Unable 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.

bash
docker run -d --name web -p 127.0.0.1:18080:80 --memory 256m --cpus 0.5 nginx:1.29-alpine
Output
be97b4cbd8b84b8451a874f4fde61481d86d3c5ec99f0f87ff7366aecb3ff026

The long string is the container ID. Here is what each option did.

What each docker run option does
OptionMeaning
-dRun in the background and print the container ID
--name webGive the container a name to use instead of the ID
-p 127.0.0.1:18080:80Forward port 18080 on the host loopback address to port 80 in the container, host side first
--memory 256mCap the memory charged to the container
--cpus 0.5Limit it to the CPU time of half a CPU, spread over any cores, without reserving a core
nginx:1.29-alpineThe 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.

bash
docker ps --filter name=^web$
curl -sI http://127.0.0.1:18080 | head -3
Output
CONTAINER 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 GMT

Up 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.

bash
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)
done
Output
pid    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.

What each namespace gave the container in the test
NamespaceWhat the container getsEvidence below
PIDIts own process numbers, with its main process as PID 1ps inside shows nginx as PID 1, its workers and the ps command itself
NetworkIts own interfaces, addresses and portsOnly lo and eth0 inside, versus the host interface list
MountIts own root filesystem built from the image/etc/os-release says Alpine inside and Ubuntu on the host
UTSIts own hostnamebe97b4cbd8b8 inside, vm on the host
IPCIts own shared memory and message queuesA separate namespace ID
UserNot separate by default, so UIDs match the hostUID 101 inside is UID 101 outside
CgroupShared with the host on this cgroup v1 setup, private by default on cgroup v2The same namespace ID on both sides
TimeIts own boot and monotonic clocks, while wall clock time stays sharedDifferent 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.

bash
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-release
Output
be97b4cbd8b8
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.

bash
docker exec web ps
Output
PID   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 ps

PID 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.

bash
docker top web
Output
UID                 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 process

The 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.

bash
docker exec web uname -r
uname -r
Output
6.18.44-fc-v1157
6.18.44-fc-v1157

The 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.

bash
docker exec web id nginx
id redis
Output
uid=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.

bash
docker inspect web --format 'NanoCPUs={{.HostConfig.NanoCpus}} Memory={{.HostConfig.Memory}}'
Output
NanoCPUs=500000000 Memory=268435456

500000000 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.

bash
docker stats --no-stream web
Output
CONTAINER 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     3

Check 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.

bash
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then echo "cgroup v2"; else echo "cgroup v1"; fi
Output
cgroup v1

This 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.

bash
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}}' hog
Output
Killed
Killed
exit=137
OOMKilled=true ExitCode=137

Exit 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.

bash
docker exec web sh -c 'echo "hello" > /usr/share/nginx/html/note.txt'
docker diff web | grep html
Output
C /usr/share/nginx/html
A /usr/share/nginx/html/note.txt

Remove 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.

bash
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.txt
Output
404

Keep Data With a Docker Volume

A Docker volume keeps data outside the container, so it survives when the container is removed and recreated.

bash
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.txt
Output
kept
Where container data lives and whether it survives
StorageLives inSurvives docker rmUse it for
Writable layerThe container itselfNoTemporary files and caches
Named volumeStorage managed by DockerYesDatabases, uploads, app data
Bind mountA host folder you chooseYes, it is on the hostConfig files and code you edit on the host
tmpfs mountHost memoryNo, lost when the container stopsScratch 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.

Container states seen in the test
CommandStateStatus shownWhat is true now
docker create --name demo nginx:1.29-alpinecreatedCreatedWritable layer exists, no process yet
docker start demorunningUp Less than a secondThe main process runs
docker pause demopausedUp Less than a second (Paused)Processes frozen but still in memory
docker unpause demo then docker stop demoexitedExited (0) Less than a second agoProcess ended, writable layer kept
docker rm demononeNo row returnedContainer and its writable layer deleted
docker run -d --name flaky --restart on-failure nginx:1.29-alpine sh -c 'sleep 1; exit 3'restartingRestarting (3) Less than a second agoDocker 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.

Settings that change how much a container can do
SettingEffectWhat it does not do
--user 101:101 or USER in the imageThe app runs as a non root UIDIt is still that same UID on the host without a user namespace
--cap-drop ALL then add back only what is neededRemoves privileged kernel operationsDoes not stop the app reading files it can already reach
--read-onlyMakes the container root filesystem read onlyDoes not protect mounted volumes
User namespace remapping or rootless modeContainer root maps to an unprivileged host userOff by default, and some images need changes
--privileged or --pid hostGrants extensive privileges and device access, or exposes the host process listRemoves much of the isolation, so avoid it
Membership of the docker groupLets a user control the daemonDocker 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.

bash
docker run --rm --user 101:101 --read-only --cap-drop ALL nginx:1.29-alpine sh -c 'id; touch /etc/x'
Output
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.

Container or virtual machine, by situation
SituationBetter fitWhy
Web apps, APIs, databases and self hosted tools on one serverContainerQuick to start and update, easy to move with the image
The same app in development and productionContainerThe image pins the libraries and versions
Code from users you do not trustVirtual machine or a sandboxed runtimeA shared kernel is a weaker boundary
A custom kernel, kernel modules or a different OSVirtual machineContainers cannot bring their own kernel
Windows apps on a Linux hostVirtual machineWindows images need a Windows kernel
A full graphical desktop for daily workVirtual machineContainers suit application workloads better than complete desktops
A single program that already installs cleanlyEitherA 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.

bash
docker run -d --name web-public -p 8080:80 nginx:1.29-alpine
docker port web-public
ss -ltnH '( sport = :8080 )' | awk '{print $4}'
Output
80/tcp -> 0.0.0.0:8080
0.0.0.0:8080

Here 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.

Checklist before running containers in production
CheckCommand or setting
Pin a version tag, and the digest where repeat deployments must matchnginx: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 hostdocker 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.

bash
docker image inspect --format '{{index .RepoDigests 0}}' nginx:1.29-alpine
Output
nginx@sha256:5616878291a2eed594aee8db4dade5878cf7edcb475e59193904b198d9b830de

Put 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.

bash
docker logs CONTAINER_NAME
docker inspect -f '{{.State.Status}} {{.State.ExitCode}} {{.State.OOMKilled}}' CONTAINER_NAME
Common container problems
What you seeLikely causeFix
Exited right after docker runThe main process finished or crashedRead docker logs for that container and check its command
Exited (137) with OOMKilled trueMemory limit reachedRaise --memory or lower the app memory use
Port is already allocatedAnother container or program holds the host portPick another host port in -p
Data gone after an updateData was in the writable layerMove it to a named volume or bind mount
exec format errorThe executable does not match the host, often a different CPU architectureCompare the image architecture with uname -m and pull or build for your platform
Permission denied on a mounted folderOwnership, mode, groups or a security policy do not allow that UIDCheck 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

  1. Docker Docs, What is a container
  2. Open Container Initiative, About the OCI
  3. Linux manual page, namespaces(7)
  4. Docker Docs, Resource constraints
  5. Docker Docs, Runtime metrics and cgroup versions
  6. Docker Docs, Storage
  7. Docker Docs, Port publishing and mapping
  8. Docker Docs, Docker Engine security
  9. Microsoft Learn, Isolation modes for Windows containers

Written and tested by VPS Lane EngineeringWe run every step on real servers before publishing and update the article when the software changes.