Home

Install Gitlab in a LXD Container

Run a gitlab instance in a lxc container and use a shared folder to sync the backups with a remote host.

lxc launch ubuntu:16.04 gitlab
lxc config device add gitlab backup-share disk path=/data source=/data/gitlab

Host Setup

To access the gitlab instance with ssh, you have to set a static ip to your container.

Open your lxd_dnsmasq.conf file or create it if you don't have one.

sudo vim /etc/default/lxd_dnsmasq.conf
dhcp-host=gitlab,10.0.10.2

Then restart your lxd bridge to apply the config.

sudo service lxd-bridge stop && sudo service lxd-bridge start

Port forwarding for ssh access to the container host:2222 -> 10.0.10.2:22

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2222 -j DNAT --to-destination 10.0.10.2:22

Cleaning ACL on the backup shared directory /your/backup/

setfacl -R -b /data/gitlab

Create git user on the host to map with git user in the container

groupadd -g 100998 git
useradd -u 100998 -g 100998 git

Setting ACL on the hosts backup directory

setfacl -R -m u:user:100998:rwX,g:100998:rwX /data/gitlab

Container Setup

Open a shell on your gitlab container

lxc exec gitlab bash

Install required packages

apt-get install curl openssh-server ca-certificates postfix

Add the gitlab repositories to your dependencies

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash

Intall and reconfigure gitlab. Don't forget to configure the backup path of your gitlab.

apt-get install gitlab-ce
gitlab-ctl reconfigure

Edit cronjobs for your backup automation with crontab -e

Setup backup crontab [every day at 1am]

0 1 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1

Sources