Skip to main content

Docker Containers Explained: What Docker Is, What a Container Is and When to Use One

In this article

Docker is a tool for packaging a program together with everything it needs to run, and then running that package in isolation on any Linux machine. The package is called an image: a read-only snapshot of a filesystem containing the operating system libraries, the language runtime, your code and a note of which command to start. A Docker container is a running instance of an image. It is an ordinary process on the host, given its own private view of the filesystem, network and process list by the Linux kernel. The result is that it behaves as if it had a machine to itself.

That is the whole idea. A container is not a virtual machine; it shares the host's kernel and starts in a fraction of a second. It is not a deployment strategy, a backup or a security product either. What it gives you is the certainty that the thing you tested is byte-for-byte the thing you shipped. The image built on a laptop is the image that runs on the server.

This guide explains images and containers precisely, what Docker is not, and what a Django site looks like inside one. It also covers when a small business website actually benefits from it as opposed to just gaining another layer to debug.

Images and containers, precisely

An image is built from a Dockerfile, a short text file of instructions. The instructions start from a base image such as python:3.12-slim, copy in the requirements file, install the packages, copy in the code, and declare the start command. Each instruction adds a layer, and layers are cached, so rebuilding after a one-line code change takes seconds because only the final layers change. The finished image is pushed to a registry (Docker Hub, GitHub Container Registry or a private one) with a tag, and any machine with Docker can pull it by name.

A container is what you get when you run an image. Docker asks the kernel for a new set of namespaces, so the process sees only its own files, its own network interface and its own process tree. It uses control groups to cap how much memory and processor it can take. The container gets a thin writable layer on top of the read-only image. Anything written there disappears when the container is removed, which is the single most important thing to understand about containers. They are disposable by design, and anything that must survive, such as a database or uploaded files, lives in a volume mounted from outside.

The shipping container analogy is accurate as far as it goes. The standard box meant any crane could lift any cargo; the standard image means any host can run any application. The analogy breaks at the point where people assume the box protects what is inside. It isolates; it does not secure.

What Docker is not

  • Not a virtual machine. A VM runs its own kernel on emulated hardware and takes minutes to boot. A container is a process with a restricted view of the host. On a Mac or Windows laptop, Docker Desktop quietly runs one small Linux VM and puts all the containers inside it. That is why it feels slower there than on a Linux server.
  • Not a security boundary of the same strength as a VM. Containers share a kernel, so a kernel vulnerability can cross them. Running untrusted code from different customers in containers on one host is a job for stricter tooling; running your own application's services is fine.
  • Not orchestration. Docker runs containers on one machine. Running them across several machines, restarting failed ones and rolling out new versions is what Kubernetes, Nomad and the managed platforms do. Most small business sites never need that layer.
  • Not a backup. The image contains the code, not the data. The database and uploads still need their own backups.
  • Not faster. The application runs at the same speed inside a container as outside. The savings are in setup time and consistency, not response time.
  • Not maintenance-free. A base image carries its own operating system packages, and they age. An image built a year ago has a year of unpatched libraries in it until it is rebuilt. That is one of the reasons regular maintenance includes rebuilding images, not just updating code.

What a Django site looks like in Docker

A typical Django project becomes three or four containers that talk to each other over a private network. They are the web application running under Gunicorn, PostgreSQL, Redis, and often a worker for background jobs such as sending email or generating PDFs. Docker Compose describes the set in one file, so the whole stack starts with a single command on a new laptop.

FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN python manage.py collectstatic --noinput
CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3"]

Three things about that file matter more than the syntax. The requirements are copied and installed before the code, so a code change does not reinstall every package. Secrets are not in the image; they arrive as environment variables when the container starts, so the same image serves staging and production. And the database is not in the image at all. It runs in its own container with a volume, or more often in production as a managed PostgreSQL service outside Docker entirely. That is because a database wants persistent disk and careful backups rather than disposability.

Deploying then means building the image once, pushing it to the registry, and telling the server to pull the new tag and restart. The old container keeps serving until the new one is healthy. If the new release is bad, rolling back is starting the previous tag again, which takes seconds and is the part developers end up valuing most.

When a small business site benefits

Docker earns its place in four situations.

  1. More than one service. Once a site has a web process, a database, a cache and a worker, running them identically on every developer's machine and on the server by hand becomes error-prone. Compose makes the set reproducible.
  2. More than one developer, or a change of developer. "Clone the repository and run one command" is a far better handover than a page of setup notes. It is also what makes a web application built in stages easy to pick up months later.
  3. Deploying to a managed platform. Render, Fly.io and similar platforms either build an image from your Dockerfile or take one you built, so the image is the deployment artefact whether you chose Docker or not.
  4. Rebuilding under pressure. If the server dies, a documented image plus a database backup is a far shorter road back than a server configured by hand over two years. It is the practical half of a disaster recovery plan.

Against that, a single small Django site on a VPS runs perfectly well as a Gunicorn process managed by systemd behind Nginx, with a short deploy script. For that site Docker is a second thing to learn, a second set of logs to read and a second place for a disk to fill up.

The choice of hosting usually decides it: a managed platform means containers whether you like them or not, and a plain VPS leaves it up to you. We use containers where a project has several services or will be handed between people, and plain processes where it will not. A platform with accounts, payments and background jobs is almost always the first kind.

Containers and scaling

Containers make it easy to run a second copy of the web process, which is where people start thinking about scale. The order of operations still matters: a single well-sized server with caching serves most business sites comfortably, and adding copies only helps once that machine is measurably full.

When that day comes, the stateless design that containers push you towards is exactly what a load balancer needs in order to spread requests across more than one copy. That design means sessions in the database or Redis and uploads in object storage rather than on local disk. Building that way from the start costs nothing; it just means not writing files to the container's own disk.

Questions people ask

What is the difference between a Docker image and a container?

The image is the read-only package: files, runtime, code and start command. The container is a running copy of it with a thin writable layer that is thrown away when the container is removed. One image can run as many containers at once, which is how the same build serves staging and production.

Is Docker a virtual machine?

No. A virtual machine has its own kernel and emulated hardware. A container is a normal process on the host that the kernel has walled off from the others. That is why a container starts in under a second and uses only the memory the application itself needs.

Do I need Docker to host a website?

No. A single Django or static site runs well without it. Docker becomes worth the learning curve when there are several services, several people or a platform that expects images.

Is Docker free?

Docker Engine, the part that runs on Linux servers, is open source and free. Docker Desktop, the Mac and Windows application, is free for individuals and small businesses and requires a paid subscription above a company size that Docker sets.

Where to start

If you are a business owner, the useful question for your developer is not "do we use Docker". It is "could a stranger rebuild this site from the repository and a backup, and how long would it take". If the answer is a Dockerfile and twenty minutes, the detail does not matter. If the answer is a shrug, that is the thing to fix, and a container is one good way to fix it. If you are the developer, write the Dockerfile for the next project rather than retrofitting the current one, and keep the database outside it.