amuck-landowner

Install LXC + Web Panel on Ubuntu 13.04 w/NAT

jarland

The ocean is digital
Kicking off my new blog, blog.jarland.me, with a guide for something that I have enjoyed recently. I know some other hobbyists here might enjoy the experiment in something they may not have done before. So I thought I'd share.

Sometimes OpenVZ is more than I want on a dedicated server. Sometimes I want a new kernel. LXC is container based "virtualization" that provides a native performance alongside the host operating system, much like OpenVZ does. Additionally, sometimes I want to separate the environment which houses my individual services but I don't necessarily need a bunch of IPs. I might have ZNC in one, a web server in another, nothing that particularly conflicts, I just prefer the service isolation. This is how I achieve the result that I desire.

 

 

Here is a look at the web based administration panel that you will be working with.

screenshot01s.png


 

On a fresh installation of Ubuntu 13.04, run the following command:

 


Code:
apt-get update && apt-get -y upgrade && apt-get -y install lxc

 

After this finishes, it's time to install LXC Web Panel.

 


Code:
wget http://lxc-webpanel.github.io/tools/install.sh -O - | bash

Once this installs, visit http://[your IP or hostname]:5000 and login with the credentials below.

 


Code:
Username: admin
Password: admin

 

Obviously you are going to want to change that inside the panel. While I enjoy writing, I am going to intentionally leave out how to create a new LXC container inside this web interface. I'll give you a hint, it involves "Create CT."

 

LXC Web Panel is going to create a new container for you with an internal IP address. Use the following guide:

 


Code:
[one] - Port to forward to the container.
[two] - Your primary network interface. Usually eth0 or eth1.
[three] - The IP of the container.
[four] - The port you want to send the traffic to on the container.

 

To replace the correct parts of the following iptables command:

 


Code:
iptables -t nat -A PREROUTING -m tcp -p tcp --dport [one] -j DNAT -i [two] --to-destination [three]:[four]

For example, if my LXC container is 10.0.1.3 and I want to forward web requests, on port 80, to the container, I would use the following:

 


Code:
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 80 -j DNAT -i eth0 --to-destination 10.0.1.3:80

Now here's the fun part. How do we control the container via command line? Here's the most useful ones for basic functionality.

 


Code:
List containers:
lxc-list


Enter container:
lxc-attach —-name [container name]


Start container:
lxc-start —-name [container name]


Stop container:
lxc-stop —-name [container name]
 
Last edited by a moderator:

WebSearchingPro

VPS Peddler
Verified Provider
Awesome tutorial, how LXC looking as a contender against OpenVZ in the marketplace with their adoption by canonical?
 

jarland

The ocean is digital
Awesome tutorial, how LXC looking as a contender against OpenVZ in the marketplace with their adoption by canonical?
My take is that it just isn't mature enough to replace OpenVZ for selling containers. Can be done, of course, just has a few quirks with resource limitations from time to time, and in general doesn't feel like it's built for the kind of isolation and administration that OpenVZ is. For personal use, I like it better than OpenVZ.
 

Echelon

New Member
Verified Provider
I must say, it seems lightweight enclosures just got interesting again. Seems this may very well be the space to watch in the future yet again.
 

jarland

The ocean is digital
I was looking at LXC before, and then I saw docker.io which is LXC but 100% better. Here is a nice web ui for it too:

https://github.com/ehazlett/shipyard
Agreed. Although the initial hurdle of understanding it is a tad more steep than the way this panel handles LXC. I'd recommend anyone new to it start with this and then give docker a try, so that they have a better understanding of it's foundation. May just be me though, maybe docker makes more sense at first glance to others.
 

peterw

New Member
I use docker for application environments. Simple one click install of tomcat with all libs and configs. virt-manager is supporting lxc too.
 
Top
amuck-landowner