What is Container?
A unit of execution that bundles an application with the libraries and settings it needs and runs it isolated from other processes while sharing the host OS kernel. On Linux it is built from namespaces, which separate the view of process IDs, the network, mounts and so on, and cgroups, which limit the use of CPU and memory. It is lighter and faster to start than a virtual machine that boots a whole OS, but because it shares the kernel it cannot run a kernel of a different kind of OS from the host. Containers are created from container images and are created and managed with tools such as Docker and Kubernetes.
Japanese name: コンテナ
Container appears in 19 practice questions across 2 topics, including Cloud and Container Basics, OS & Hardware.
Field: Cloud and Container Basics
How it differs from a virtual machine
Virtual machines each run an OS, kernel included, on a hypervisor. A container does not boot an OS; it runs as an isolated process on the host kernel, so it often starts in under a second, and many can be packed onto one machine. On the other hand, its isolation relies on kernel features and is not as strong as that of a virtual machine. Where strong isolation is needed, containers are sometimes run inside lightweight virtual machines.
FAQ
Can a container use a different Linux distribution from the host?
Yes. An image contains user-space files such as commands and libraries, so they can come from another distribution. The kernel, however, is shared with the host, so uname -r shows the host kernel and features the host kernel lacks are unavailable.
Why can Linux containers run on Windows or macOS?
Tools such as Docker Desktop run a small Linux virtual machine and execute the Linux containers in it. Linux containers always need a Linux kernel somewhere.