Ok, here is some serious stuff this time, it is work. I am gonna show how I check my code running functional tests in a virtualized environment. It is going to be interesting, I promise.
I mostly use LXC containers because they are light-weight, fast and very simple to manage. Let's go through it from the very first steps.
I use Ubuntu servers for testing. Other distros are also ok, but the LXC containers are very well supported by Ubuntu, in fact I think Ubuntu is where the LXC containers were born. I use LXC under Ubuntu for several years now, it is pretty stable, fortunately it did not give me much headache. Nice and easy, I don't have time to play with these, it is as I said before, work. :)
Here is what I run on one of the servers. Just an example, other releases will do, some stable Ubuntu Server (or maybe desktop if that's available):
pipas@core2:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.6 LTS Release: 16.04 Codename: xenial pipas@core2:~$
As a first step we need to make sure the containers will see the Internet, that they are routed to the local area network and through the router they can reach the software repositories we need. In other words we need to make sure the containers will get an IP that they can use all the way to the Internet.
For this the bridge-utils package has to be installed. Installing it would not change the server configuration, but we need to install it because we will reconfigure the network and without this package we would loose the internet connection. Anyway, an apt install bridge-utils is a must, then we will have this:
pipas@core2:~$ dpkg -l bridge-utils Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-==============-============-============-================================= ii bridge-utils 1.5-9ubuntu1 amd64 Utilities for configuring the Lin pipas@core2:~$
Now we have to change the network configuration. I have this, for a recipe:
pipas@core2:~$ cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface #auto enp5s1f0 #iface enp5s1f0 inet dhcp auto br0 iface br0 inet static bridge-ifaces enp5s1f0 bridge-ports enp5s1f0 up ifconfig enp5s1f0 up address 192.168.0.18 netmask 255.255.0.0 gateway 192.168.0.1 dns-search homelab.local dns-nameservers 192.168.0.2 192.168.0.3 iface enp5s1f0 inet manual
Here the name of my network interface is enp5s1f0 and the original configuration that was put there by the Ubuntu install program was this:
auto enp5s1f0 iface enp5s1f0 inet dhcp
Well, I replaced it with a static configuration that uses a bridge, called br0. That's just it, it is a server, wanted a static IP configuration and wanted to have a bridge that my containers can use so I have this change.
When I changed the network configuration I rebooted the server. I don't do it very often, but this change is pretty big and reboot is a good way to be sure. If the server comes back with a working network configuration it will do so any day.
Next we will need the LXC command line tools. For this the package lxc1 has to be installed. Well, it is version 2, but the name is lxc1. Programmers are weird like that.
root@core2:~# dpkg -S $(which lxc-ls) lxc1: /usr/bin/lxc-ls root@core2:~# dpkg -l lxc1 Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-==============-============-============-================================= ii lxc1 2.0.11-0ubun amd64 Linux Containers userspace tools root@core2:~#
Anyway, install this package and they will provide a set of tools to create, start, stop and destroy containers.
Before we do so we need to change a configuration file, /etc/lxc/default.conf. The lxc1 package gave us this simple configuration file that controls what network settings the containers will have:
root@core2:~# cat /etc/lxc/default.conf lxc.network.type = veth lxc.network.link = br0 lxc.network.flags = up lxc.network.hwaddr = 00:16:3e:xx:xx:xx root@core2:~#
Here, originally the lxcbr0 was the designated lxc.network.link, we change that to br0, the name of the device we just created for the containers to get a network.
And that's all, now the lxc1 is installed and set up, we can create containers. There are a number of lxc-* commands we can use. One word of advice though: I always run these commands as root. It is possible to use them as an unprivileged user, but it is a whole lot of complication and headache related to the unprivileged containers and we want to save our energies for the real work.
Soooo.... here is a quick reminder about what we had here and what you need to do if you want the same:
- Install the bridge-utils package on the container server or on your desktop.
- Set up the networking by modifying the /etc/network/interfaces so that it uses static IP and a bridge called br0.
- Install the lxc1 package that holds the container management scripts.
- Modify the /etc/lxc/default.conf, replace lxcbr0 to br0 so that your new containers will see your network the same way the container server does.
- If you choose to run the lxc-* scripts you should do it as root.
Finally some words about the screenshots. They are a teaser, a reminder showing what we want to achieve here. Easy and fast tools to create containers, clusters, colorful, informative screens. These first steps are for sure boring and dry, but there is hope. I promise it will be a lot more interesting soon.