The situation: you have rented this big server, and you want to utilize it better. But you don’t want to install all services together, rather you want to separate the various services into containers.

LXC is very useful for this purpose.

My LXC scripts help to make setting up a machine even easier.

The scripts are available at Github:

These scripts have been tested on Ubuntu 14.04, and I recommend this for this exercise.

To install the LXC scripts, and LXC 1.0.x, you can install an Ubuntu package, see

apt-get install apt-transport-https
echo 'deb /' >> /etc/apt/sources.list
apt-get update
apt-get install lbslxcscripts

The scripts now live in /root/scripts.

There are several scripts to create a virtual machine:

cd /root/scripts
# ./   <release, default is precise> <arch, default is amd64> <autostart, default is 1>
./ 10-UbuntuDesktop 10 trusty
./ 20-FedoraDesktop 20
./ 30-CentosDesktop 30 7
./ 40-DebianMachine 40 wheezy

Please note: I did not look into creating unprivileged containers yet!

These commands are useful for working with the containers:

# start the container
lxc-start -d -n 30-CentosDesktop
# list all containers
lxc-ls -f
# list all containers and their Linux distribution
# login to the container
ssh root@
# stop the container
lxc-stop -n 30-CentosDesktop
#destroy the container
lxc-destroy -n 30-CentosDesktop

I want fixed IP addresses for my virtual machines. The IP address for container with ID 40 will be

To make a port available from the outside, you can call this:

# This will forward the port 2010 of the host machine to the container running at IP, port 22.
./ 10 22
# This will forward the port 8010 of the host machine to the container running at IP, port 80.
./ 10 80

For websites, I use Nginx on the host machine, to manage http and https (SSL) websites on a single IP:

# the host will listen for and forward all traffic to port 80
# SSL will be setup if these files exist: /var/lib/certs/ and
./ 10

There is a script that backs up all LXC settings and IP Tables rules and Nginx configuration of your containers:

./ myusername

This scripts will upgrade the host and all containers, depending on their Linux distribution. You can run it every night with a cronjob:

Setting up a server hosting several containers with some useful LXC scripts
Tagged on: