Integration of collabora online on a Nextcloud behind NAT on a KVM hypervisor

August 23, 2019 in debian, hypervisor, linux, nextcloud ‐ 3 min read

This one had me struggle quite a bit.
I felt like this is something that cannot possibly be super hard to setup.
Before running Nextcloud in a VM I remember the setup to be quite trivial.

And once again it has proven to be true that there are only three networking issues. DNS DNS and DNS. But lets take a step back.

I am running a Nextcloud for my family and wanted to integrate collabora.

This is the How-To I used: https://www.linuxbabe.com/cloud-storage/integrate-collabora-online-server-nextcloud-ubuntu-16-04

Collabora, much like Google Docs or Office365, enables you to edit documents online in your browser. Collabora is a child of Libreoffice Online. The Idea is to still perform well even if 20 people or more are working on a document simultaneously.

The average collabora installation guide is using the collabora\code docker container. It expect you to run it in a “classical” nextcloud setup in wich the Apache or Nginx Server is run on the Aplication Layer of the Host Operating System of the Server.

image

In such a setup the docker container is running in the kernelspace of the host machine that is hooked up to the internet.

image

If we now add a layer of virtualisation things become a little more tricky.

image

The docker container is still running in the same kernelspace as the nextcloud instance. However the NAT is having some effects on the DNS resolution.

The docker container gets run using the hostname for the subdomain that will be used by the webserver for the rewrite rules interacting with the docker container.

sudo docker run -t -d -p 127.0.0.1:9980:9980 -e 'domain=nextcloud\\.your-domain\\.com' --restart always --cap-add MKNOD collabora/code

If we run this setup without nat, the docker container can resolve nextcloud.your-domain.com to 127.0.0.1.

Then the container can speak to the nextcloud using the loopback interface.
Behind a nat, this is not working.

A simple change does the trick.
We will have to edit the hosts file inside the docker conainer.

EDIT: Docker has a parameter to perform this task (since version 17) called –add-host. Using this option your changes wont be lost if the container restarts (e.g. if the host reboots). Lets say the IP of your Nextcloud behind the NAT is 192.168.122.10. Then you will have to start the container like this:

sudo docker run -t -d -p 127.0.0.1:9980:9980 -e 'domain=nextcloud\\.your-domain\\.com' --restart always --cap-add MKNOD --add-host=nextcloud.your-domain.com:192.168.122.10 --add-host=office.your-domain.com:192.168.122.10 collabora/code

General container debugging

EDIT: I will leave this bit in for general purpose docker container debugging.

Check docker ps -a to find the name the collabora docker container has been assigned. Then start a shell inside the container using docker exec -i -t /bin/bash.

There we edit the /etc/hosts file and add two lines.
One for office.your-domain.com and one for nextcloud.your-domain.com. It worked best for me using the IP address of the virtual machine.

Beeing lazy I did run apt update and apt install vi to have an editor inside of the container. You could also just echo it into the hosts file.

image

Afterwards you also need to edit the /etc/hosts file of the VM.
To be able to properly communicate with the container I had to have office.your-domain.com resolve to 127.0.0.1 rather then my public IP.

image

Cheers,
Ori