System administrators are very used to handle several different complex services that run interconnected and in parallel on high availability servers. In this scenario, it is hard to understand all the architecture and application connections in a single server, so you do not break it when trying to fix or update something. It is also common to bump into servers that are not even updated accordingly, because the system administrators are so afraid of architecture the server was build, that they usually prefer not to touch these servers. This is the kind of issue that we will try to solve in this article.
With the advent of virtualization and tools used to handle nested operating system, some engineers realized system administrators' apprehension and tried to decrease it by using containers isolation, pre-installed applications and control version concepts. They eventually came up with Docker, that is a layer over Linux containers, and could be seen as a lightweight virtualization.
On the Docker architecture, each application runs in a single container, and each container supports only one application, meaning that all files in a single container exist solely to support that application. In this scenario, a container is a minimal operating system plus the application it will run. One of the most common minimal operating system is Ubuntu Core, that is based on, as you might expect, Ubuntu.
Ubuntu Core and Docker on an IBM POWER8 server is a good combination for customers looking for an efficient and agile method to deploy complex workloads on the cloud.
What is Ubuntu Core?
Ubuntu Core is the minimal Ubuntu installation ideally for small environments. It contains just the basic OS layer that supports any other software to run over it.
It is basically a 200MB Linux rootfs that contains around 196 packages that can be extended to be a full distro. Since it contains the dpkg and apt tools, you can install whatever you want to tailor it to your needs.
Ubuntu core follows traditional Ubuntu release, and it started to ship for ppc64el architecture at 14.04, and the latest release is 14.10. You can also find daily build for Ubuntu core at Ubuntu Core daily builds website. In this article we are going to use Ubuntu Core version 14.04 on a standanrd 14.10 Ubuntu Docker host.
Ubuntu Core could be used on containers, Docker, chroot and virtualization environments.
What are Linux Containers?
Linux Containers is the basic technology behind Docker. A Linux container is the technology that would enable an operating system virtualization on Linux, providing all the infrastructure to isolate different containers.
Linux containers rely basically on two technologies that enable the existence of containers:
- Cgroups: a Linux kernel technology that enables mainly process isolation using name spaces and resource limitation.
- LXC tools: a userspace daemon and a client tools that enables container management.
In order to guarantee that Linux Containers work fine on your machine, you can run a script that guarantee that your environment is sane. To do so, as root run:
Install LXC package
# apt-get install lxc
Run the lxc-checkconfig
- Guarantee that everything is enabled, as:
Figure 1: Verify that your server supports containers.
What is Docker?
Docker is an infrastructure to deploy applications/software inside a Linux container, so, instead of having a full set of applications being used on the same machine, you can have an application per container, and deploy multiple containers.
For each container, you can have a version control for it, which means that you can 'commit' and 'revert' changes, so, you handle a complex set of applications breaking them in easier containers.
Using Docker hub, you can also upload, share and download already pre configured containers for your environment, so, instead of installing a complex application, you can download a container with an already installed application.
Installing Docker in Ubuntu on Power
In order to install docker on Ubuntu 14.10, you should do the following steps as root:
Install Docker repository in Ubuntu:
# echo deb http://ftp.unicamp.br/pub/ppc64el/ubuntu/14_10/docker-ppc64el/ utopic main >> /etc/apt/sources.list
Update the archive index
# sudo apt-get update
Install the docker package
# apt-get install docker.io
This is a example of the package being installed on a 2-sockets POWER8 S822-L machine.
(you may click on these images to see a larger version of the image)
Figure 2: Docker.io package being installed on Ubuntu 14.10
Creating the Ubuntu Core image in Docker
- Download Ubuntu Core based on 14.04 version
Import the files into docker
# cat trusty-core-ppc64el.tar.gz | docker import - ubuntucore 3ad6c6616b921b10a414238a226fb39eef85d8249ac7d767e84e275aaf90ab65
Guarantee that the image was created:
# docker images
Assure that your image is running fine:
# docker run ubuntucore ls
Figure 3: Listing the fresh installed ubuntucore image
Figure 4: Assuring that the container is running
Using a preloaded Ubuntu Core image
If you want to use a default Ubuntu Core image for ppc64el, you don't need to do the step below, you can just install an already installed image. In order to do so, you need to be registered at Docker Hub website, which is similar to a github for docker images. Once you have registered there, just login using docker and then search for a ppc64el image.
# docker login
Figure 5: Authenticating in Docker hub
# docker pull image.
This is an example that I have been using on my personal registry.
Figure 6: Download Ubuntu Core 14.04 for POWER
This is going to create a Ubuntu core image in your system, which would enable you to play with Docker and Ubuntu Core on POWER. Once you have that, you can list the docker images and you are going to find the image leitao/ubuntucore as part of your images. As always, you can run any command on this image using:
# docker run image <command>
Commiting and reverting changes
Once you have your image running, you can change it as you want, and commit the changes. For example, let's install a package into the my ubuntucore image:
After git is installed you can check that there is a modification, using:
Later, you can see what files were modified after the change, using the container ID, as:
If you like your change, you can commit it using docker commit command and then upload the changed image using docker push command.
Automating container creation
It is possible to automate the image creation using the concept of Dockerfile, which describes how a Docker image is created starting from a base image.
A Dockerfile is generally used to create custom images, as you can execute command and copy files into an already existing image, giving it a personal content.
A Dockerfile is a plain text that uses a small set of commands to create a customized image. In the following example we are going to create an image with mongodb installed, and copy some customized etc files.
This is how the Dockerfile looks like:
from ubuntucore # use the initial image called ubuntu core maintainer "Breno Leitao" # The author for this new image run apt-get install -y mongodb # Run a command to install mongodb into the image copy /srv/mongodb/etc /etc # Copy the directory /srv/mongodb/etc to inside the image /etc
In order to run this Dockerfile, you need to save it and run the following command on the directory that contains this file:
# docker build .
Once you run it, you are going to have a new image that is based on the ubuntucore image, with the package mongodb installed and the files from the 'host' /srv/mongodb/etc copied to the container /etc directory.