LinuxKit GITHUB repository has already crossed 1800 commits, 3600+ stars & been forked 420+ times since April 2017 when it was open sourced by Docker Inc for the first time. LinuxKit today support dozens of platforms which falls under Cloud, local hypervisor & Bare metal systems categories. Recently, arm64 support was added and I published a blog post which talks about building LinuxKit for the minimalist Raspberry Pi 3. Improved Kubernetes support has been another enhancement and you can follow my blog to build Multi-Node Kubernetes cluster using LinuxKit. In case you want to build Multi-Node Kubernetes cluster using the newly added CRI-containerd & Moby, don’t miss out this blog post.
In case you’re very new to LinuxKit , it is a toolkit for building secure, portable & lean operating systems for containers. It uses moby tooling to build system images. Everything runs in a container. LinuxKit uses the linuxkit tool for building, pushing and running Virtual Machine images. The moby
tool assembles a set of containerized components into in image. The simplest type of image is just a tar
file of the contents.The YAML configuration specifies the components used to build up an image . All components are downloaded at build time to create an image. The image is self-contained and immutable, so it can be tested reliably for continuous delivery.
A Look at LinuxKit Architecture
At the base of LinuxKit, there is a modern Linux kernel which specifies a kernel Docker image, containing a kernel and a filesystem tarball, eg containing modules. The minimal init is the base init
process Docker image, which is unpacked as the base system, containing init
, containerd
and a few tools. It is basically built from pkg/init/.
The onboot containers are the system containers, executed sequentially in order. They should terminate quickly when done. The services is the system services, which normally run for the whole time the system is up. The .files
are additional files to add to the image
What’s New in LinuxKit?
Below are the list of new features which has been introduced in LinuxKit recently –
Early this year, I wrote a blog post which talks about how to manually create LinuxKit ISO image and then mount it to run it under Oracle VirtualBox. The method was complicated as it required converting VMDK file into .VDI format first and then registering the VM using VBoxManage CLI.
Test-Drive LinuxKit OS on Oracle VirtualBox running on macOS Sierra
Now with the introduction of linuxkit run vbox
CLI, it is just a matter of 2-3 minutes to get it on VirtualBox up and running.
Under this blog post, we will see how LinuxKit OS can be built and run on Oracle VirtualBox in just 2 minutes.
Pre-requisites:
- MacOS Sierra
- Docker for Mac installed on MacOS
- Docker Up and Running
- Oracle VirtualBox
Clone the LinuxKit Repository:
[simterm]
$git clone https://github.com/linuxkit/linuxkit
[/simterm]
Building the LinuxKit Tool
[simterm]
$cd linuxkit
$make
[/simterm]
Place LinuxKit under the right executable PATH:
[simterm]
$cp bin/linuxkit /usr/local/bin/
[/simterm]
Building ISO image for VirtulBox.
Before we go ahead and build ISO for Virtualbox, let us look at the newly introduced command line option:
Now you can use `LinuxKit build` option to build the ISO image. Let us look into this sub-command:
Let’s run the below command to build iso-bios format of docker.yml which can be found under linuxkit/examples directory under LinuxKit repository.
[simterm]
$linuxkit build -format iso-bios --name testbox docker.yml
[/simterm]
This builds up ISO image as shown below:
Running the ISO for VirtualBox
Justin Cormack, a LinuxKit maintainer did a great job in introducing a new CLI option linuxkit run box
as shown below:
Run the below command to initiate LinuxKit OS on VirtualBox in the form of VM:
[simterm]
$linuxkit run vbox --iso testbox.iso
[/simterm]
This will initiate a VM called testbox under Virtualbox as shown below:
You can verify under VirtualBox Manager:
Open up Console to see LinuxKit running under this new VM:
So, you can access either through terminal or directly under the console but NOT both at the same time.
Accessing Docker Service Container
To access the Docker service container, first list out the running service containers:
[simterm]
$ctr tasks ls
[/simterm]
This will list out the running service containers as shown below:
Lets us enter into docker service container and verify Docker release version:
[simterm]
ctr tasks exec -t --exec-id 502 docker sh
[/simterm]
This will allow it to enter into shell as shown. Run docker version
command to verify the currently available Docker release.
Please note that networking doesn’t get enabled by default for these service container. You will need to manually enable “Cable Connected” option under VirtualBox > Settings > Network > Advanced to get the IP address assigned to the network interface.
I have raised this issue with LinuxKit Team and you can track it here.
Let us go back to the terminal and try to pull few Docker images as shown below:
Wow ! So we have Docker service container running inside LinuxKit OS on top of Oracle VirtualBox platform flawlessly.
Did you find this blog helpful? Feel free to share your experience. Get in touch @ajeetsraina.
Interested to read more on LinuxKit? Check this out –
Building a secure Docker Host VM on VMware ESXi using LinuxKit & Moby
Building a Secure VM based on LinuxKit on Microsoft Azure Platform
Building Docker For Mac 17.06 Community Edition using Moby & LinuxKit
If you are looking out for contribution/discussion, join me at Docker Community Slack Channel.