Linux Format

Dip into Containers

Contain your applicatio­ns, run a mailserver and have a whale of a time.

-

those of you who are proud to be called Linux greybeards or have ever repaired a broken Linux install with a live disc will be familiar with the chroot command. This changes the root directory of the current shell, and if done into a directory containing a Linux install, effectivel­y pivots into it. Provided you do some bind-mounting trickery first, this enables you to use all the software and libraries in the /chroot directory with the kernel and hardware from the working install. This is how most desktop Linux installers work.

If you throw in some fairly complicate­d kernel technologi­es (namely resource management with cgroups and isolation with namespaces), then modern containers are just a natural evolution of this idea. Coming from another direction, modern containers are what you get if you sacrifice some of the isolation of VMs and throw away the requiremen­t to have a complete operating system. This makes them more portable and easier to spin up than VMs. From a utilitaria­n point of view, containers enable applicatio­ns to be packaged once and then be installed anywhere without any additional dependenci­es (except an appropriat­e container runtime).

installing Docker

There’s a docker package in the Ubuntu repos, but it has nothing at all to do with containers, it being a dock applet for the venerable WindowMake­r window manager. To install Docker on Ubuntu 18.04 you can use the Snap (available straight from the Software Centre) or you can add the Docker repo. The latter is slightly more work, but is also kept slightly more up to date than the snap, so let’s do that. First ensure everything is up to date: $ sudo apt update && sudo apt upgrade Then install some addons and helpers for Apt, and add the Docker GPG key: $ sudo apt install git apt-transport-https ca-certificat­es curl software-properties-common $ curl -fsSL https://download.docker.com/linux/ ubuntu/gpg | sudo apt-key add - Now add the Docker Ubuntu repo and update the package lists: $ sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable” $ sudo apt update Finally we can install the Docker Community Edition with the following: $ sudo apt install docker-ce

Mail with added moo

Back in lxf240 we showed you how to set up your own mail server. It took the best part of three pages, and it was fairly primitive. A wise reader wrote to us and told us about the mailcow:dockerized project by which a much more fully featured mail server (including a webmail interface, spam blocking and support for Two Factor Authentica­tion and other tokens) could be set up more or less at the click of a button. Naturally, we were intrigued.

Of course, nothing’s ever that simple and as before we won’t cover all the malarkey of setting up your domain name and MX records. You’ll also need to make

sure that your router/firewall forward/allow the appropriat­e ports. Check https://mailcow. github.io/mailcow-dockerized­docs/prerequisi­te-system/ and indeed the rest of the excellent documentat­ion for more info.

The mailcow:dockerized applicatio­n suite is actually about two dozen different containers connected together by the magic of Docker Compose. Docker Compose uses a YAML (YAML Ain’t Markup Language) file that defines all the services and volumes used by the applicatio­n and gets all of the associated containers talking to one another. Volumes are a mechanism for persisting data generated by containers, if we didn’t use them (or some alternativ­e) then every time we stopped a container all the data it had generated would vanish. If we were to start the container again, it would be as if ‘twere the first time all over again. Our mailcow:dockerized suite defines six volumes.

Get docking

Docker Compose isn’t shipped via the repo we added earlier, so grab it straight from GitHub: $ curl -L https://github.com/docker/compose/ releases/download/$(curl -Ls https://www.servercow. de/docker-compose/latest.php)/docker-compose$(uname -s)-$(uname -m) > docker-compose $ sudo mv docker-compose /usr/local/bin/ $ sudo chmod +x /usr/local/bin/docker-compose Alternativ­ely, if you don’t like all that dollar sign voodoo just visit https://github.com/docker/ compose/releases and grab whatever is the latest release. Then move the binary to /usr/local/. Now we can almost clone the mailcow:dockerized git repo, which we’ll put in the /opt directory. This needs to be done as root (we’ll prefix commands run as root with #), so run: $ sudo -i # cd /opt Then we must check the output of umask , it should be 0022 (so our files can be read by regular users). If it’s not then take matters into your own hands with umask 0022 . Now we can clone the repo with: # git clone https://github.com/mailcow/mailcowdoc­kerized And then we begin the configurat­ion: # cd mailcow-dockerized # ./generate_config.sh You’ll be asked for the domain name (FQDN) of your mail server and your timezone. If you just want to experiment, you can make up a domain and add it to your hosts file. For example, we used mail.lxfmail.net and changed the 127.0.0.1 line in /etc/hosts to: 127.0.0.1 localhost mail.lxfmail.net Now peruse the configurat­ion file with: # nano mailcow.conf If, like us, you’re just playing with a made-up hostname, you’ll want to set SKIP_LETS_ENCRYPT=y otherwise the set-up process will try and obtain a certificat­e for a nonexisten­t domain, which will fail miserably. Now we grab the manifold images that constitute mailcow:dockerized (which will take a couple of minutes even on a fast connection), and bring them up: # docker-compose pull # docker-compose up -d

You should see lots of satisfying debug output. If (like us) you were already running a webserver (or any other service that uses ports required by Mailcow, do check the prerequisi­tes doc mention earlier) then this command will fall over. Mailcow’s web service can happily work via a reverse proxy, or you could just shut your webserver down. Hopefully it all works out, then you can visit your Mailcow install at the address specified and configure everything to your liking. When your done just run docker-compose stop from the

Mailcow directory.

GETTING DOCKER “TO INSTALL DOCKER ON UBUNTU 18.04 YOU CAN USE THE SNAP FROM THE SOFTWARE CENTRE OR ADD THE DOCKER REPO”

 ??  ?? This tweet pretty much sums up why Docker is so useful.
This tweet pretty much sums up why Docker is so useful.
 ??  ??
 ??  ?? Holy mailcow Batman, it works! Log in with the default credential­s, then change them as quick as you can.
Holy mailcow Batman, it works! Log in with the default credential­s, then change them as quick as you can.
 ??  ?? Make your mail secure with Time-based One Time Pad authentica­tion, or some such.
Make your mail secure with Time-based One Time Pad authentica­tion, or some such.

Newspapers in English

Newspapers from Australia