Over a million developers have joined DZone.
Platinum Partner

Lightweight Virtualization with LXC

· Cloud Zone

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 Ubuntu.

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:

ifconfig lxcbr0

Now add new nameserver in your resolv.conf (my lxcbr0 IP address was

echo "nameserver" >> /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:

ssh ubuntu@alen

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.

The Cloud Zone is brought to you in partnership with Iron.io. Learn how to build and test their Go programs inside Docker containers.


Published at DZone with permission of Alen Komljen , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}