Dev tools

What Is a Docker Container? A Plain Guide

What a Docker container is, how it differs from an image and a virtual machine, how it works under the hood, the commands you need, and common mistakes.

By OmniAI Editorial · Nov 23, 2026 · 9 min read

A Docker container is a running, isolated instance of an application together with everything it needs: its code, runtime, libraries and settings. It runs as an ordinary process on the host's operating system, but with its own view of the filesystem, network and process list, so it behaves as if it had a small machine to itself. Containers start in seconds, run the same way on a laptop, a server or the cloud, and can be thrown away and recreated at will.

The idea solves an old problem: "it works on my machine." Instead of installing an application and its dependencies on each server and hoping versions match, you package everything into an image once and run it as a container anywhere Docker runs. This guide explains what a Docker container is, how it differs from an image and from a virtual machine, how it works under the hood, the essential commands, how data and networking work, and the mistakes to avoid.

Docker Container at a Glance

ItemDetail
What it isA running, isolated instance of a container image
Built fromAn image: a read-only, layered template with the app and its dependencies
IsolationLinux namespaces (what it can see) and control groups (what it can use)
Operating systemShares the host's kernel; no separate guest OS
Start-up timeTypically seconds or less
PersistenceContainer filesystem is temporary; use volumes for data that must survive
Created withdocker run (or docker create plus docker start)
StandardsImages and runtimes follow Open Container Initiative (OCI) specifications
HistoryDocker was released as open source in March 2013

What Is a Docker Container?

What is a Docker container, in practice? Think of it as a sealed box with one job, such as a web server, a database or a background worker. Inside the box: the application and exactly the libraries and tools it needs. Outside: the host machine, which only needs Docker (or another compatible container runtime) installed.

When you run a container, Docker:

  1. Takes the image you name, downloading it from a registry such as Docker Hub if it isn't already local.
  2. Adds a thin writable layer on top of the image's read-only layers.
  3. Creates isolated namespaces so the process has its own filesystem view, process IDs, network interfaces and hostname.
  4. Applies resource limits with control groups (cgroups), such as maximum memory or CPU.
  5. Starts the image's configured command as the container's main process.

When that main process exits, the container stops. Delete the container and its writable layer goes with it, while the image remains, ready to start a fresh copy.

Docker Container vs Image

A stack of four image layers linked to three containers, each topped by a thin orange layer
An image is a stack of read-only layers; each container adds its own thin writable layer on top.

Docker container vs image is the most common point of confusion. The relationship is like a class and an object, or a recipe and a meal:

ImageContainer
What it isA read-only templateA running (or stopped) instance of an image
StateNever changes once builtHas a writable layer that changes as it runs
Built bydocker build from a Dockerfiledocker run from an image
Stored inLocal image store and registriesLocal container store on one host
How manyOne imageMany containers can run from the same image
LifetimeKept until deletedOften short-lived and replaced

An image is built in layers. Each instruction in a Dockerfile adds a layer:

FROM node:22-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

Layers are cached and shared: ten containers from the same image share one copy of the read-only layers on disk, and rebuilding after a code change reuses the unchanged dependency layer. That's why the order of Dockerfile instructions matters: put things that change rarely, such as dependency installation, before things that change often, such as your source code.

Docker Container vs Virtual Machine

Left: three virtual machines on hypervisor and hardware layers; right: four containers on a shared orange layer above hardware
Virtual machines each carry a full guest OS on a hypervisor; containers share the host kernel.

On Docker container vs virtual machine: both isolate applications, but at different levels.

Docker containerVirtual machine
What's virtualisedThe operating system's view (processes, filesystem, network)The hardware
Guest OSNone; shares the host kernelA full operating system per VM
SizeOften tens to hundreds of MBUsually several GB
Start-upSeconds or lessTypically tens of seconds to minutes
DensityMany per hostFewer per host
Isolation strengthGood; one shared kernelStronger; separate kernels
Runs a different OS kernelNo (Linux containers need a Linux kernel)Yes

On Windows and macOS, Docker Desktop runs Linux containers inside a lightweight Linux virtual machine, because the containers need a Linux kernel. In the cloud, containers usually run inside virtual machines anyway, combining the two: VMs for strong isolation between customers, containers for packaging and density within each VM.

Docker Container Commands

These Docker container commands cover most daily work:

TaskCommand
Run a container in the background, mapping a portdocker run -d --name web -p 8080:3000 myapp:1.0
List running containersdocker ps
List all containers, including stoppeddocker ps -a
See logsdocker logs -f web
Open a shell insidedocker exec -it web sh
Stop and startdocker stop web / docker start web
Remove a containerdocker rm web (add -f to stop and remove)
Show resource usedocker stats
Inspect configurationdocker inspect web
Build an imagedocker build -t myapp:1.0 .
Clean up unused datadocker system prune

Useful docker run options include --rm (delete the container when it exits), -e KEY=value (environment variables), -v or --mount (attach storage), --memory and --cpus (resource limits) and --restart unless-stopped (restart policy for long-running services).

If commands fail with a permissions error on Linux, our guide to fixing Docker permission denied walks through the causes.

Data: Volumes and Bind Mounts

A container's writable layer disappears when the container is removed, so anything that must survive, such as database files or uploads, belongs outside it:

Storage typeWhat it isGood for
Named volumeStorage managed by DockerDatabases and persistent app data
Bind mountA host folder mapped into the containerLocal development with live code reloading
tmpfs mountMemory-only storageTemporary, sensitive scratch data

Example: docker run -d -v pgdata:/var/lib/postgresql/data postgres:17 keeps the database files in a volume named pgdata, so you can upgrade or recreate the container without losing data.

Networking

Each container gets its own network interfaces. By default, containers join a bridge network on the host; you publish ports with -p host:container to reach them from outside. Containers on the same user-defined network can reach each other by name, which is how a web container finds its database:

docker network create app
docker run -d --name db --network app -e POSTGRES_PASSWORD=secret postgres:17
docker run -d --name web --network app -p 8080:3000 -e DATABASE_HOST=db myapp:1.0

For multi-container apps, Docker Compose describes all the services, networks and volumes in one compose.yaml file and starts them with docker compose up.

Containers in Production

Running one container on one machine is simple. Running hundreds across many machines, with restarts, scaling, rolling updates and load balancing, needs an orchestrator. Kubernetes is the most widely used; our comparison of Docker vs Kubernetes explains how they fit together. Docker isn't the only way to run containers either: tools such as Podman run the same OCI images without a central daemon, as our guide to Docker vs Podman covers.

Security Basics

  • Don't run as root inside the container unless you must; add a USER instruction to the Dockerfile.
  • Use small, trusted base images and rebuild regularly to pick up security patches.
  • Never bake secrets into images. Pass them at runtime through environment variables or a secrets manager.
  • Limit resources so one container can't starve the host.
  • Scan images for known vulnerabilities in your build pipeline.
  • Remember the shared kernel: a kernel vulnerability affects every container on the host, which is why multi-tenant platforms add VM-level isolation.

Common Mistakes

  • Storing data in the container's writable layer and losing it on removal.
  • Using `latest` tags in production, so you can't tell which version is running.
  • Huge images from copying build tools and caches into the final image; use multi-stage builds.
  • One container doing many jobs instead of one process per container.
  • Ignoring logs and health checks.

FAQ

Is a Docker container a virtual machine?

No. A container is an isolated process sharing the host's kernel. A virtual machine runs a complete operating system on virtualised hardware.

Does a container keep data when it stops?

Yes, a stopped container keeps its writable layer. The data is lost when the container is removed, unless it's stored in a volume or bind mount.

Can one image run several containers?

Yes. You can start any number of containers from the same image; each gets its own writable layer and isolation.

What's the difference between Docker and container technology?

Docker is a set of tools for building, sharing and running containers. A container is the isolated running instance itself, which other tools can also run.

Do Docker containers work on Windows and Mac?

Yes, through Docker Desktop, which runs Linux containers in a lightweight virtual machine. Windows also supports native Windows containers for Windows applications.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog