What is a container?

A container is a running process, or a small group of processes, isolated by the Linux kernel and started from an image that carries its files and settings.

What is a container made of?

An image, a writable layer, a set of kernel isolations and some configuration. The image supplies the read-only file system and the default command. The writable layer on top holds whatever the container changes at run time. Namespaces give it its own process tree, network stack, mounts and host name; control groups cap its CPU, memory and process count. Configuration adds environment variables, mounted volumes, published ports and the user it runs as. Our Containerisation article explains the kernel features behind it.

What does a container look like from inside?

Like a tiny, nearly empty machine. The main process sees itself as process ID 1, a short list of other processes, a file system that is the image's, a network interface with a private address and a host name of its own. There is usually no init system, no SSH server and no cron; the container lives exactly as long as its main process. That is why a container whose command exits immediately appears to "stop at once": it did its job and ended.

docker run --rm -it --name probe alpine:3.20 sh -c 'echo pid $$; hostname; ip -brief addr; ps'
docker inspect --format '{{.State.Pid}} {{.HostConfig.Memory}} {{.NetworkSettings.IPAddress}}' web
nsenter -t "$(docker inspect -f '{{.State.Pid}}' web)" -n ss -ltn

The last line enters only the network namespace of a running container to list its listening sockets with the host's own tools.

What is the life cycle of a container?

StateMeaningCommand that leads there
CreatedConfigured, file system prepared, not runningcreate
RunningMain process alivestart or run
PausedProcesses frozen by the cgroup freezerpause
ExitedMain process ended; writable layer still keptstop or process exit
RemovedContainer and writable layer deletedrm

A stop sends SIGTERM to process 1 and, after a grace period, SIGKILL. Applications should handle SIGTERM to finish requests and close connections cleanly; otherwise every restart drops work in progress.

Where do its files go?

Changes land in the writable layer, which is deleted with the container. Anything worth keeping belongs in a volume or a bind mount from the host. Writing heavily into the writable layer is also slower than writing to a volume, because the overlay file system must copy files up from the image on first change. Logs should go to standard output, where the runtime collects them, rather than to files inside the container.

How is a container connected to the network?

Usually through a virtual Ethernet pair to a bridge on the host, with NAT for outbound traffic and port publishing for inbound. Alternatives are host networking, where the container shares the host's network stack directly, useful for performance-sensitive services such as game servers, or none at all for batch jobs. On a server here, with one public IPv4 address and an IPv6 block, publish container ports on loopback and let a reverse proxy on the host route public traffic by host name.

How are its resources limited?

Through cgroup settings applied at start. Memory limits stop a leaking container from exhausting the host; CPU quotas or shares divide processor time; a process limit prevents fork bombs; I/O weights balance disk access. Without limits, a container can use everything on the machine. On ESSENTIAL-M with 12 and 64 GB DDR5, giving each of twenty services an explicit memory limit makes the total predictable.

How secure is a single container?

Reasonably, with care. A container shares the host kernel, so a kernel vulnerability can be a path out. Reduce the risk by running as a non-root user, dropping capabilities, using a read-only root file system where possible, applying the runtime's default seccomp profile, keeping the host kernel patched and avoiding --privileged. For untrusted code, run containers inside a virtual machine for an extra boundary. Our Containers or virtual machines article compares the two isolation models.

Where should I run my first containers?

On any Linux server with Docker or Podman installed, which takes minutes on every distribution we offer. A small host such as ESSENTIAL-1 at $38.40 a month is plenty to learn and to run a handful of services in production. Our Docker article walks through images, volumes and Compose, and Container management covers running them over time.

Related pages

Containerisation

Packaging an application with its libraries so it runs the same everywhere: namespaces, cgroups, images, runtimes and running containers on bare metal.

Read more

Docker

The tool that made containers mainstream: engine and client, Dockerfiles, images, volumes, networks and Compose, with practical notes for running it on bare metal.

Read more

Containers or virtual machines

Containers share the host kernel; virtual machines bring their own. Isolation, density, start times and when to combine both on one dedicated server.

Read more

Container management

The everyday work of running containers: images and registries, updates, resource limits, logs, monitoring and security on your own servers.

Read more

Questions and answers

Is a container a virtual machine?

No. A container is an isolated group of processes sharing the host kernel. A virtual machine runs its own kernel on virtual hardware.

Why does my container stop immediately after starting?

A container runs only as long as its main process. If that command finishes or crashes, the container exits; check its logs for the reason.

What happens to files written inside a container?

They go to the writable layer and are deleted when the container is removed. Keep important data in volumes or bind mounts.

How do I stop a container from using all memory?

Set a memory limit when starting it, for example with the memory option in Docker or Podman, so the kernel caps its usage.

Can a container run as root safely?

It is better not to. Run processes as a non-root user, drop unneeded capabilities and avoid privileged mode to limit damage from an escape.