On Host
Instructions for setting up the host system is given below
sudo apt install systemd-container mmdebstrap
sudo [auto-apt-proxy] mmdebstrap --include=systemd-container,auto-apt-proxy,sudo bullseye /var/lib/machines/gitlab-bullseye
Note: auto-apt-proxy is optional (this will speed up package downloads if you have apt-cacher-ng setup)
Enable systemd-networkd
sudo systemctl enable systemd-networkd sudo systemctl start systemd-networkd
Basic configuration of the container can be setup by connecting to it via
sudo systemd-nspawn --bind=/home/<username> -D /var/lib/machines/gitlab-bullseye --machine gitlab-bullseye
Note: This will make /home/<username> from host also available in the container in the same path, so a users files will also be shared with the container making it easy to share files between host and container.
Inside container
For root access (use machinectl login in multiple terminals), setup a root password and create a normal user with sudo access (--uid option can be skipped if the <username> is first user on the host, ie, uid 1000)
adduser --uid <uid on host for username> <username> gpasswd -a <username> sudo passwd
Enable systemd-networkd inside the container,
systemctl enable systemd-networkd
Optional: Setup hostname in /etc/hostname (use your favorite editor)
gitlab-bullseye
and /etc/hosts
127.0.0.1 localhost gitlab-bullseye ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters
Press Control+D to exit.
On Host again
sudo mkdir -p /etc/systemd/nspawn
Create /etc/systemd/nspawn/gitlab-bullseye.nspawn and add the following lines
[Exec] Boot=yes PrivateUsers=no PrivateUsersChown=no [Files] Bind=/home/<username> [Network] VirtualEthernet=yes
To start the container,
sudo machinectl start gitlab-bullseye
and to connect to the container,
sudo machinectl login gitlab-bullseye
or
sudo machinectl shell gitlab-bullseye
Press ^] three times within 1s to exit from the virtual terminal of the container after you logout (Control + D).
To stop the container, run:
sudo machinectl stop gitlab-bullseye