What is a Linux Container?

What is a Linux container, and how is it different from Docker, or virtual machines.

What is a Linux Container?

LXC or Linux containers are a containerization method similar to application containers like Docker, but with a few key differences and use cases. Like application containers, Linux containers use Linux namespaces and cgroups to create isolation of the running container from the host system. Where the technology differs from application containers, is in use cases and immutability. Where application containers are meant to be mostly ephemeral, Linux containers are designed to be persistent and meant for Operating System virtualization.

Virtual machines or VMs are designed to be a fully contained representation of server or computer. The hypervisor helps to emulate the underlying hardware each operating system inside a VM container would need to run, as if it was running on the bare metal of a machine. VMs require more overhead to run, since the emulation is of a full piece of hardware for each VM a host is running. On the other hand LXC containers use the host kernel to create a shared kernel for the containerized Operating system. This allows for running multiple OSs on a single host, but without the additional overhead of running full VMs for each Operating System.

LXC containers are useful when it is necessary to run multiple operating systems or when legacy or outdated operating systems are needed to run legacy applications. The storage for the container is persistent between reboots/shutdowns creating a lightweight VM for the additional OS or legacy application.

Although application containers can have persistent storage through a mechanism called volumes, which allows the mounting of folders/filesystems from the host to locations within the application container, the design philosophy of application containers is such that once built, the container is immutable, allowing for rapid deployment for scaling the application.

As you can see there is overlap in the technology used for Application containers, Linux containers, and Virtual Machines. The key to utilizing them efficiently, is using the right tool, or combination of tools for the job. We will explore VMs and hypervisors in another post.