CNTR: Lightweight OS Containers
Total Page:16
File Type:pdf, Size:1020Kb
CNTR: Lightweight OS Containers Jorg¨ Thalheim, Pramod Bhatotia Pedro Fonseca Baris Kasikci University of Edinburgh University of Washington University of Michigan Abstract fundamental to achieve high efficiency in virtualized datacenters and enables important use-cases, namely Container-based virtualization has become the de-facto just-in-time deployment of applications. Moreover, standard for deploying applications in data centers. containers significantly reduce operational costs through However, deployed containers frequently include a higher consolidation density and power minimization, wide-range of tools (e.g., debuggers) that are not required especially in multi-tenant environments. Because of all for applications in the common use-case, but they these advantages, it is no surprise that containers have seen are included for rare occasions such as in-production wide-spread adoption by industry, in many cases replacing debugging. As a consequence, containers are significantly altogether traditional virtualization solutions [17]. larger than necessary for the common case, thus increasing the build and deployment time. Despite being lightweight, deployed containers often include a wide-range of tools such as shells, editors, CNTR1 provides the performance benefits of lightweight coreutils, and package managers. These additional tools containers and the functionality of large containers by are usually not required for the application’s core function splitting the traditional container image into two parts: the — the common operational use-case — but they are “fat” image — containing the tools, and the “slim” image included for management, manual inspection, profiling, — containing the main application. At run-time, CNTR and debugging purposes [64]. In practice, this significantly allows the user to efficiently deploy the “slim” image and increases container size and, in turn, translates into then expand it with additional tools, when and if necessary, slower container deployment and inefficient datacenter by dynamically attaching the “fat” image. resource usage (network bandwidth, CPU, RAM and disk). To achieve this, CNTR transparently combines the two Furthermore, larger images degrade container deployment container images using a new nested namespace, without time [52, 44]. For instance, previous work reported that any modification to the application, the container manager, downloading container images account for 92% of the de- or the operating system. We have implemented CNTR in ployment time [52]. Moreover, a larger code base directly Rust, using FUSE, and incorporated a range of optimiza- affects the reliability of applications in datacenters [50]. tions. CNTR supports the full Linux filesystem API, and it is compatible with all container implementations (i.e., Given the impact of using large containers, users Docker, rkt, LXC, systemd-nspawn). Through extensive are discouraged from including additional tools that would otherwise simplify the process of debugging, evaluation, we show that CNTR incurs reasonable perfor- mance overhead while reducing, on average, by 66:6% the deploying, and managing containers. To mitigate this image size of the Top-50 images available on Docker Hub. problem, Docker has recently adopted smaller run-times but, unfortunately, these efforts come at the expense of 1 Introduction compatibility problems and have limited benefits [13]. Containers offer an appealing, lightweight alternative to To quantify the practical impact of additional tools on VM-based virtualization (e.g., KVM, VMware, Xen) that the container image size, we employed Docker Slim [11] relies on process-based virtualization. Linux, for instance, on the 50 most popular container images available on provides the cgroups and namespaces mechanisms the Docker Hub repository [10]. Docker Slim uses a that enable strong performance and security isolation combination of static and dynamic analyses to generate between containers [24]. Lightweight virtualization is smaller-sized container images, in which, only files needed by the core application are included in the final 1Read it as “center”. image. The results of this experiment (see Figure5) are encouraging: we observed that by excluding unnecessary 2 Background and Motivation files from typical containers it is possible to reduce the 2.1 Container-Based Virtualization container size, on average, by 66.6%. Similarly, others have found that a only small subset (6.4%) of the container Containers consist of a lightweight, process-level form images is read in the common case [53]. of virtualization that is widely used and has become a cor- nerstone technology for datacenters and cloud computing CNTR addresses this problem2 by building lightweight providers. In fact, all major cloud computing providers containers that still remain fully functional, even in uncom- (e.g., Amazon [2], Google [16] and Microsoft [4]) offer mon use-cases (e.g., debugging and profiling). CNTR en- Containers as a Service (CaaS). ables users to deploy the application and its dependencies, Container-based virtualization often relies on three while the additional tools required for other use-cases are key components: (1) the OS mechanism that enforces supported by expanding the container “on-demand”, dur- the process-level isolation (e.g., the Linux cgroups [41] ing runtime (Figure1 (a)). More specifically, CNTR splits and namespaces [40] mechanisms), (2) the application the traditional container image into two parts: the “fat” im- packaging system and runtime (e.g., Docker [9], Rkt [38]), age containing the rarely used tools and the “slim” image and (3) the orchestration manager that deploys, distributes containing the core application and its dependencies. and manages containers across machines (e.g., Docker During runtime, CNTR allows the user of a container to Swarm [12], Kubernetes [22]). Together, these com- efficiently deploy the “slim” image and then expand it with ponents enable users to quickly deploy services across additional tools, when and if necessary, by dynamically machines, with strong performance and security isolation attaching the “fat” image. As an alternative to using a “fat” guarantees, and with low-overheads. image, CNTR allows tools from the host to run inside the Unlike VM-based virtualization, containers do not container. The design of CNTR simultaneously preserves include a guest kernel and thus have often smaller memory the performance benefits of lightweight containers and footprint than traditional VMs. Containers have important provides support for additional functionality required by advantages over VMs for both users and data centers: different application workflows. 1. Faster deployment. Containers are transferred and The key idea behind our approach is to create a new deployed faster from the registry [44]. nested namespace inside the application container (i.e., 2. Lower resource usage. Containers consume fewer “slim container”), which provides access to the resources in resources and incur less performance overhead [62]. the “fat” container, or the host, through a FUSE filesystem 3. Lower build times. Containers with fewer binaries interface. CNTR uses the FUSE system to combine the and data can be rebuilt faster [64]. filesystems of two images without any modification to the Unfortunately, containers in practice are still unnecessar- application, the container implementation, or the operating ily large because users are forced to decide which auxiliary system. CNTR selectively redirects the filesystem requests tools (e.g. debugging, profiling, etc.) should be included between the mount namespace of the container (i.e., what in containers at packaging-time. In essence, users are cur- applications within the container observe and access) and rently forced to strike a balance between lightweight con- the “fat” container image or the host, based on the filesys- tainers and functional containers, and end up with contain- tem request path. Importantly, CNTR supports the full ers that are neither as light nor as functional as desirable. Linux filesystem API and all container implementations (i.e., Docker, rkt, LXC, systemd-nspawn). 2.2 Traditional Approaches to Minimize Containers We evaluated CNTR across three key dimensions: The container-size problem has been a significant source (1) functional completeness – CNTR passes 90 out of of concern to users and developers. Unfortunately, existing 94 (95:74%) xfstests filesystem regression tests [14] solutions are neither practical nor efficient. supporting applications such as SQLite, Postgres, and An approach that has gained traction, and has been Apache; (2) performance – CNTR incurs reasonable over- adopted by Docker, consists of packing containers using heads for the Phoronix filesystem benchmark suite [18], smaller base distributions when building the container and the proposed optimizations significantly improve runtime. For instance, most of Docker’s containers are the overall performance; and lastly, (3) effectiveness – now based on the Alpine Linux distribution [13], resulting CNTR’s approach on average results in a 66:6% reduction in smaller containers than traditional distributions. Alpine of image size for the Top-50 images available on Docker Linux uses the musl library, instead of libc, and bundles hub [10]. We have made publicly available the CNTR busybox , instead of coreutils — these differences implementation along with the experimental setup [6]. enable a smaller container runtime but at the expense of compatibility problems caused by runtime