Unikernels, Meet Docker!
Learn the differences between Linux containers, containers per VM, and unikernels.
Join the DZone community and get the full member experience.Join For Free
in november, unikernels took to the stage at dockercon eu in barcelona! as part of the cool hacks session in the closing keynote, anil madhavapeddy ( mirageos project lead), showed how unikernels can be treated as any other container. he first used docker to build a unikernel microservice and then followed up by deploying a real web application with database, webserver and php code all running as distinct unikernel microservices built using rump kernels . docker managed the unikernels just like linux containers but without needing to deploy a traditional operating system!
this kind of integration helps put unikernels into the hands of developers everywhere and combines the familiar tooling and real-world workflows of the container ecosystem with the improved security, efficiency and specialization of unikernels. we’ll finish off this post with details of how you can get involved — but first, before we go into anil’s demonstration in more detail, some background about why unikernels matter, and why it makes sense to use docker this way.
as companies have moved to using the cloud, there’s been a growing trend towards single-purpose machine images, but it’s clear that there is significant room for improvement. at present, every vm has to host a copy of the os on which the application runs, especially where strong isolation is required.
these vm-hosted applications are also affected by os vulnerabilities, including exploits that have no relation to applications’ day-to-day functions. for example, usb drivers — present in an os but irrelevant to cloud deployments — have had multiple vulnerabilities which allow arbitrary code execution. patching such code creates a needless maintenance burden.
unikernels take a different approach: application code is linked against only the os components it specifically requires to produce a specialised, single address space machine image — thus eliminating unnecessary code. built using ‘library operating system’ technology, unikernels provide many benefits compared to a traditional os, including:
- improved security properties — as unikernels contain no unnecessary code deployed, the application’s attack surface is dramatically reduced.
- smaller footprints — unikernel code bases are typically several orders of magnitude smaller than their traditional equivalents and they can be managed much more easily.
- fine-grained optimization — as unikernels are constructed through a coherent compiler tool-chain, whole-system optimization can be carried out across device drivers and application logic, potentially improving specialisation further.
- fast boot times — as unikernels can boot in less than a second, provisioning can become highly dynamic.
these benefits are particularly relevant to microservices and the developing concept of ‘immutable infrastructure’ — where vms are treated as disposable artifacts and can be regularly re-provisioned solely from version-controlled code. modifying such vms directly isn’t permitted: all changes must be made to the source code itself.
unikernels naturally lend themselves to both the microservice architecture and the concept of immutable infrastructure: both source code and generated binary are compact enough to be easily version-controlled. if the traditional stack has allowed us to move towards microservices, then unikernels will move us towards the world of immutable nanoservices.
although unikernels provide a path, there are significant challenges to their adoption in production settings. the unikernel ecosystem is only just taking off, and this new technology needs to fit in with existing workflows and tooling.
linux containers have allowed developers to move much more quickly towards microservices by allowing a traditional os to provide functionality to multiple ‘containerised’ applications sitting above it. those containers remain distinct and thus can be independently replaced or modified, a core piece of the microservices architectural pattern.
although containerization technology has been available for some time, there’s been a recent and rapid increase in the pace of adoption. the last few years have seen a proliferation of tools that make it easier to use containers at scale, including registries of ready-made images, tools for orchestration, and much more. led and fostered by docker, this has produced a vibrant, open and growing ecosystem, which is helping improve everyone’s development workflows.
with an increasing number of supported tools and infrastructure, it’s become clear that the ecosystem is about much more than just linux containers themselves. can unikernels fit in this ecosystem? if so, where would unikernels sit in relation to containers?
containers and unikernels actually sit on a continuum. on the one hand, we have the traditional method of placing a full os stack in a vm with a single application on top. a natural next step is to use containers which run on top of a single os, giving better resource usage and allowing each application to be more self-contained. when viewed this way, unikernels are just another step on this path and can be thought of as extreme, self-contained applications. the challenge is to make unikernels as easy to use as containers have become today.
the obvious first step in addressing that challenge is to integrate unikernels with the existing container infrastructure, specifically the docker tools and ecosystem. this helps us to get unikernels into the hands of developers everywhere, with a widely used and understood packaging model and runtime framework, effectively by making unikernels just another type of container.
it also unlocks the entire container ecosystem of tools for use with unikernels, including orchestration and whatever else may be around the corner. adoption of existing toolchains will accelerate the progress of unikernels and also demonstrates the flexibility and breadth of the docker ecosystem. by using docker to abstract away the complexity of the underlying os, a developer can choose how they "containerize" their application, whether they target a traditional linux container, or a new unikernel ‘container’.
it is exactly these first steps enabling developers to build and run real-world unikernel microservices, using existing docker tools, which anil demonstrated at dockercon eu today!
first he used docker to build a unikernel microservice, and then he ran a cluster of unikernels to deploy a real web application with database, webserver and php code. the whole build system is wrapped in an easy-to-use dockerfile and each microservice is turned into a specialised unikernel. those unikernels run in their own kvm virtual machine with hardware protection. docker manages the unikernel containers just like linux containers, including networking!
this early work makes unikernels a usable target for a docker deployment! since unikernels can now be managed by docker, it can bring all the benefits of the existing ecosystem to the orchestration and management of unikernels.
the demo consisted of using the typical components found in a lamp stack, specifically nginx, mysql and php. these unmodified, off-the-shelf components were built using the docker toolchain but instead of the typical os they were built as unikernels! a cluster of these unikernels was created where each of them was specialized for the particular app they were running. watch the screencast below for more details!
the demo described here is just the beginning. there are many implementations of unikernels and there’s plenty of work ahead to ensure they can all reap the benefits of integration, as well as improving docker itself to make the most of these new technologies. look over the collection of unikernel projects and contribute your experiences to this blog!
Published at DZone with permission of Amir Chaudhry. See the original article here.
Opinions expressed by DZone contributors are their own.