Containers Not Just For Docker | Performance Magic

Ramblings from a Sysadmin

September 20, 2017

Containers Not Just For Docker

Over the past year (or more really) containers has been a big thing and specifically Docker, and I suspect so much so that many people believe that docker and container are synonymous.

This is far from the truth. Docker is really a nice wrapper that uses containers (or should that be name-spaces?) to provide a method of distributing and deploying a single application.

Containers are really just a name-space in Linux which lets you control some of the resources within that name-space. It also can do fun things like renumbering your PIDs inside the name space starting from 1 again. If you look at the process list on the host though, you will see that all the name-spaced (containerised) processes all have PIDs with the default (root?) name-space. As many others have alluded to, it’s also not easy to see what name-space a particular process belongs to. Hopefully this will be fixed, but I digress.

Really the point of this blog is to discuss LXC and how you can use it to containerise old operating systems. I have a number of clients still running EL5 environments for whatever reason, and running those on sane H/W or virtualisation is becoming increasingly difficult.

I was spurred on by Wim Coekaerts recent blog that discusses creating an EL5 container inside an EL7 host. I wondered, how much work would it be to migrate an existing EL5 VM to a EL7 hosted EL5 LXC Container?

Well here goes, this is what I did to achieve the above idea. I have deployed this a few times now with great success.

As per Wim’s post, I allocated a new Ethernet device to the host, and since this was basically a 1:1 mapping I didn’t put the /container file structure on a specific file-system instead choosing to use what was already available on the host.

One thing that Wim doesn’t mention is the requirement of lxc to use wget. Thus when you make sure you install wget along with lxc:

yum install -y wget lxc

Now create your container. We need this at least once, to save some of the specifics that the template uses to make the container work. (more on this in a moment)

lxc-create -n test-01 -t oracle -- -R 5.latest

Now you want to present the root file-system from the original VM as another disk on this host. I chose xvdg for this purpose, and the original VM was simple enough to have just 2 partitions, root and swap. Let’s mount this in place inside the container space.

cd /container/test-01
mv rootfs{,.orig}
mkdir rootfs
echo  "/dev/xvdg1 /container/test-01/rootfs ext3 defaults,noatime,_netdev 0 2" >> /etc/fstab
mount /container/test-01/rootfs

Now let’s get the original VM ready to boot as a container. Remember before making any changes, make sure you have a full backup you can restore to.

First let’s get into the root file-system location: cd /cotainer/test-01/rootfs

Since the container doesn’t need to manage any file-systems, we need to empty fstab. > etc/fstab

Now let’s setup inittab and a special wrapper for mingetty called maygetty.

cp ../rootfs.orig/etc/inittab etc/
cp ../rootfs.orig/sbin/maygetty sbin/

Lastly let’s configure /dev to have some devices so the container can boot and you can talk to it.

cp -af ../rootfs.orig/dev/* dev
ln lxc/tty1 /dev/tty0

The last line there is a bit of hack to make the boot process less noisy as some processes look for tty0.

As per Wim’s post, lets edit the config and setup the network, and then we can boot our container with: lxc-start -n test-01.

Last but not least, login and clean up any daemons or startup processes that aren’t required and are failing during boot. You can see the boot process by passing -F to lxc-start.

These are the ones that I deleted:

chkconfig --del auditd
chkconfig --del iscsid
chkconfig --del iscsi
chkconfig --del mcstrans
chkconfig --del hidd
chkconfig --del vboxdrv
chkconfig --del portmap
chkconfig --del bluetooth
chkconfig --del pcscd
chkconfig --del irqbalance

Now that it’s booting, and all the services you expect to start are starting we should set the container to start on boot of the host.

echo " = 1" >> /container/test-01/config

And that’s it. Your container should now start automatically on reboot.

© Greg Cockburn