Lightweight Virtualization with LXC
The Cloud Zone is brought to you in partnership with Iron.io. Discover how Microservices have transformed the way developers are building and deploying applications in the era of modern cloud infrastructure.
It’s been a long time since my last post. Now I’m working with more
interesting technologies, cloud related, so you will probably see more
about that. To be more precise: OpenStack, Ceph, Juju, SaltStack, AWS,
etc. But first things first, here I will talk about Linux containers and
lightweight virtualization with LXC. Also I will show how to run it on
So what are Linux containers? The LXC package combines different Linux kernel mechanisms to provide a userspace container object, a lightweight virtual system with full resource isolation and resource control for an application or a system which is a completely different approach than system virtualization technologies such as KVM and Xen. Instead of using separate virtual systems on emulated hardware LXC started out with an efficient mechanism, existing Linux process management and added isolation. (http://lxc.sourceforge.net/)
Above means that you can easily run virtual machine on your existing Linux machine. So let’s get started with instructions. As I said i will use Ubuntu here and those instructions should work without any problems.
LXC installation and preparation:
apt-get update && apt-get install -y lxc
After installation is complete you will get lxcbr0 interface up. IP address of that interface will be DNS and gateway for new containers:
Now add new nameserver in your resolv.conf (my lxcbr0 IP address was 10.0.3.1):
echo "nameserver 10.0.3.1" >> /etc/resolvconf/resolv.conf.d/base resolvconf -u
It is time to create first container called alen:
lxc-create -t ubuntu -n alen
Creating a container can take some time. After container is created you can bring it up in daemonized mode:
lxc-start -d -n alen
Now you can connect to your machine with ssh:
You can create multiple containers with different names and each will act like separate instance. After you finish your testing you can simply stop it with:
lxc-stop -n alen
That’s it. I’m pretty sure that it will be useful to know about this technology, at least until you get OpenStack up and running. Even then you can use LXC instead of KVM or Xen for nova compute nodes. Next posts I will talk more about Ceph storage, along with instructions how to get started with it. Then you can expect more OpenStack related posts.