When speaking of virtualisation (container-wise) there are two major alternatives: Docker and LXC. If I were deploying web applications I would probably go for Docker, very easy to set up a Docker file installing nginx, php-fpm, etc and doing a few commands to set it up. Docker is not designed for running full machines, you can basically just start one command, that’s it. On the other hand, LXC, you get full machines with a minimal virtualisation layer providing excellent performance. The disadvantage is that you will use more space/memory for running something similar to full machines.

This site provides a wide selection of ready container images, however the openSUSE image is version 13.2 which is running out of support. I could use that image and upgrade it, however they ran zypper install patterns-openSUSE-minimal_base without –no-recommends so you get all sorts of interesting stuff like Mesa you will not need on a server. So I decided to build my own image. It is quite easy, you will basically just need a tarball of the rootfs and a metadata file. On an openSUSE machine the rootfs can be created very easily, thanks to the –-root option of zypper. I created a bash script to create a rootfs.tgz, just run it with the requested tarball as argument, i.e. sh make-container.sh /home/you/rootfs.tgz and you are good to go. The script looks like this

tmpdir=`mktemp -d`
echo "Creating tempdir $tmpdir" 
zypper -n --root $tmpdir ar -G http://ftp.gwdg.de/pub/opensuse/distribution/leap/42.2/repo/oss/ repo-oss
zypper -n --root $tmpdir ar -G http://ftp.gwdg.de/pub/opensuse/update/leap/42.2/oss/ repo-update 
zypper -n --root $tmpdir in --no-recommends patterns-openSUSE-minimal_base \
iputils net-tools nano timezone 
cat <<EOF > $tmpdir/etc/sysconfig/network/ifcfg-eth0
cd $tmpdir 
tar cfzv $1 * 
rm -rf $tmpdir

Now you have a tarball, you will need a metadata.yaml file:

architecture: "x86_64" 
creation_date: 1458040200 
 architecture: "x86_64"
 description: "openSUSE LEAP 42.2" 
 os: "opensuse" 
 release: "leap42.2" 

Now you need to pack the metadata.yaml into metadata.tgz. You can import the image into the lxc host in the following way:

# lxc image import metadata.tgz rootfs.tgz --alias=leap

Now you are ready to spin up an instance of the image

# lxc launch leap machinename 
# lxc exec machinename bash

That’s it. You need to set the hostname in /etc/hostname, you can use lxd to get networking and NAT.