Install GitLab in LXC container on Debian/Ubuntu

Installing GitLab in LXC or LXD is not that straightforward than one would expect. If you just try to install GitLab in an LXD container you will probably run into the following error:

---- Begin output of sysctl -e --system ----
STDOUT: * Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/protect-links.conf ...
* Applying /etc/sysctl.conf ...
STDERR: sysctl: permission denied on key 'fs.protected_hardlinks'
sysctl: permission denied on key 'fs.protected_symlinks'
---- End output of sysctl -e --system ----

Before GitLab could be installed the host requires some preparation.
Add the followings to /etc/sysctl.conf

kernel.shmall = 4194304
kernel.shmall = 4194304
kernel.sem = 250 32000 32 262
net.core.somaxconn = 1024
kernel.shmmax = 17179869184

Now reload the configuration:

cat /etc/sysctl.conf /etc/sysctl.d/*.conf | sysctl -e -p

Now you can go ahead to the container and install GitLab as described by the official instructions:
https://about.gitlab.com/install/?version=ce#debian

If you encounter the same error message when running gitlab-ctl reconfigure just run the command 3 times and it will eventually work. For further info checkout this gitlab page.