Developing in Linux Containers

In this article we will show, how you can make use of Linux Containers (LXC) in distributed and heterogeneous development cycles (TL;DR; jump to the Summary).


Usually in our development cycle, we edit the sources and run some test and/or builds by using make [ref] before we commit. This cycle is simple and perfect but might fail in some aspects we should not overlook.

The environment in which we run all our development processes matters!

The Makefile and the Python environment (make install) encapsulate a lot for us, but they do not have access to all prerequisites. For example, there may have dependencies on packages that are installed on the developer’s desktop, but usually are not preinstalled on a server or client system. Another example is; settings have been made to the software on developer’s desktop that would never be set on a production system.

Linux Containers are isolate environments and not to mix up all the prerequisites from various projects on developer’s desktop is always a good choice.

The scripts from DevOps tooling box can divide in those to install and maintain software:

and the script utils/, with we can scale our installation, maintenance or even development tasks over a stack of isolated containers / what we call the:

SearXNG LXC suite


If you see any problems with the internet connectivity of your containers read section Internet Connectivity & Docker.

Gentlemen, start your engines!

Before you can start with containers, you need to install and initiate LXD once:

$ snap install lxd
$ lxd init --auto

And you need to clone from origin or if you have your own fork, clone from your fork:

$ cd ~/Downloads
$ git clone searxng
$ cd searxng

The SearXNG suite consists of several images, see export LXC_SUITE=(... near by git://utils/lxc-searxng.env#L19. For this blog post we exercise on a archlinux image. The container of this image is named searxng-archlinux. Lets build the container, but be sure that this container does not already exists, so first lets remove possible old one:

$ sudo -H ./utils/ remove searxng-archlinux
$ sudo -H ./utils/ build searxng-archlinux

In this container we install all services including searx, morty & filtron in once:

$ sudo -H ./utils/ install suite searxng-archlinux

To proxy HTTP from filtron and morty in the container to the outside of the container, install nginx into the container. Once for the bot blocker filtron:

$ sudo -H ./utils/ cmd searxng-archlinux \
  ./utils/ nginx install
INFO:  got 429 from

and once for the content sanitizer (content proxy morty):

$ sudo -H ./utils/ cmd searxng-archlinux \
  ./utils/ nginx install
INFO:  got 200 from

On your system, the IP of your searxng-archlinux container differs from, just open the URL reported in your installation protocol in your WEB browser from the desktop to test the instance from outside of the container.

In such a earXNG suite admins can maintain and access the debug log of the different services quite easy.

In containers, work as usual

Usually you open a root-bash using sudo -H bash. In case of LXC containers open the root-bash in the container using ./utils/ cmd searxng-archlinux:

$ sudo -H ./utils/ cmd searxng-archlinux bash
INFO:  [searxng-archlinux] bash
[root@searxng-archlinux searx]# pwd

The prompt [root@searxng-archlinux ...] signals, that you are the root user in the searxng-container. To debug the running SearXNG instance use:

$ ./utils/ inspect service
use [CTRL-C] to stop monitoring the log

Back in the browser on your desktop open the service and run your application tests while the debug log is shown in the terminal from above. You can stop monitoring using CTRL-C, this also disables the “debug option” in SearXNG’s settings file and restarts the SearXNG uwsgi application. To debug services from filtron and morty analogous use:

Another point we have to notice is that the service (SearXNG runs under dedicated system user account with the same name (compare Create user). To get a shell from these accounts, simply call:

$ ./utils/ instance cmd bash

To get in touch, open a shell from the service user (searxng@searxng-archlinux):

$ sudo -H ./utils/ cmd searxng-archlinux ./utils/ instance cmd bash
INFO:  [searxng-archlinux] ./utils/ instance cmd bash
[searxng@searxng-archlinux ~]$

The prompt [searxng@searxng-archlinux] signals that you are logged in as system user searx in the searxng-archlinux container and the python virtualenv (searxng-pyenv) environment is activated.

(searxng-pyenv) [searxng@searxng-archlinux ~]$ pwd

Wrap production into developer suite

In this section we will see how to change the “Fully functional SearXNG suite” from a LXC container (which is quite ready for production) into a developer suite. For this, we have to keep an eye on the Step by step installation:

  • SearXNG setup in: /etc/searxng/settings.yml

  • SearXNG user’s home: /usr/local/searxng

  • virtualenv in: /usr/local/searxng/searxng-pyenv

  • SearXNG software in: /usr/local/searxng/searxng-src

With the use of the utils/ the SearXNG service was installed as uWSGI application. To maintain this service, we can use systemctl (compare uWSGI maintenance).

$ sudo -H ./utils/ cmd searxng-archlinux \
  systemctl stop uwsgi@searxng

With the command above, we stopped the SearXNG uWSGI-App in the archlinux container.

The uWSGI-App for the archlinux dsitros is configured in git://utils/templates/etc/uwsgi/apps-archlinux/searxng.ini, from where at least you should attend the settings of uid, chdir, env and http:

env = SEARXNG_SETTINGS_PATH=/etc/searxng/settings.yml
http =

chdir = /usr/local/searxng/searxng-src/searx
virtualenv = /usr/local/searxng/searxng-pyenv
pythonpath = /usr/local/searxng/searxng-src

If you have read the “Good to know section” you remember, that each container shares the root folder of the repository and the command utils/ cmd handles relative path names transparent. To wrap the SearXNG installation into a developer one, we simple have to create a smylink to the transparent reposetory from the desktop. Now lets replace the repository at searxng-src in the container with the working tree from outside of the container:

$ sudo -H ./utils/ cmd searxng-archlinux \
  mv /usr/local/searxng/searxng-src /usr/local/searxng/searxng-src.old

$ sudo -H ./utils/ cmd searxng-archlinux \
  ln -s /share/searx/ /usr/local/searxng/searxng-src

Now we can develop as usual in the working tree of our desktop system. Every time the software was changed, you have to restart the SearXNG service (in the container):

$ sudo -H ./utils/ cmd searxng-archlinux \
  systemctl restart uwsgi@searx

Remember: In containers, work as usual .. here are just some examples from my daily usage:

To inspect the SearXNG instance (already described above):

$ sudo -H ./utils/ cmd searxng-archlinux \
  ./utils/ inspect service

Run Makefile, e.g. to test inside the container:

$ sudo -H ./utils/ cmd searxng-archlinux \
  make test

To install all prerequisites needed for a Buildhosts:

$ sudo -H ./utils/ cmd searxng-archlinux \
  ./utils/ install buildhost

To build the docs on a buildhost Buildhosts:

$ sudo -H ./utils/ cmd searxng-archlinux \
  make docs.html


We build up a fully functional SearXNG suite in a archlinux container:

$ sudo -H ./utils/ install suite searxng-archlinux

To access HTTP from the desktop we installed nginx for the services inside the container:

$ ./utils/ nginx install
$ ./utils/ nginx install

To wrap the suite into a developer one, we created a symbolic link to the repository which is shared transparent from the desktop’s file system into the container :

$ mv /usr/local/searxng/searxng-src /usr/local/searxng/searxng-src.old
$ ln -s /share/searx/ /usr/local/searxng/searxng-src
$ systemctl restart uwsgi@searx

To get information about the searxNG suite in the archlinux container we can use:

$ sudo -H ./utils/ show suite searxng-archlinux
[searxng-archlinux]  INFO:  (eth0) filtron:
[searxng-archlinux]  INFO:  (eth0) morty:
[searxng-archlinux]  INFO:  (eth0)
[searxng-archlinux]  INFO:  (eth0) IPv6:       http://[fd42:573b:e0b3:e97e:216:3eff:fea5:9b65]