Writing /var/lib/dokuwiki/wiki.project-insanity.org/data/meta/systemd-nspawn.meta failed
systemd-nspawn
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
systemd-nspawn [2018/02/10 11:31] – 46.5.2.217 | systemd-nspawn [2021/10/31 10:42] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Prepare base image ===== | ||
+ | <code bash> | ||
+ | pacman -S arch-install-scripts | ||
+ | btrfs subvol create / | ||
+ | mkdir / | ||
+ | pacstrap / | ||
+ | systemctl enable --now systemd-networkd systemd-resolved | ||
+ | </ | ||
+ | ===== Prepare child image ===== | ||
+ | Setting UID range for container: Using a multiple of 65536, e.g. 65536 * 70 for this machine as. To match the user http (always uid 33) on the container, a user on the host with the same permissions should therefore have the UID: 65536 * 70 + 33. | ||
+ | <code bash> | ||
+ | useradd -m -u $((65536 * 70 + 33)) archlinux-dokuwiki | ||
+ | mkdir / | ||
+ | chown -R archlinux-dokuwiki: | ||
+ | </ | ||
+ | PrivateUsers parameter is here equal to 65536 * 70 | ||
+ | <code bash> | ||
+ | systemd-nspawn -nD / | ||
+ | </ | ||
+ | <code bash> | ||
+ | pacman -S ansible | ||
+ | wget " | ||
+ | machinectl shell root@archlinux-dokuwiki /bin/bash -c " | ||
+ | machinectl shell root@archlinux-dokuwiki /bin/bash -c " | ||
+ | git clone ... | ||
+ | cd ... | ||
+ | ansible-galaxy install -r requirements.yml | ||
+ | sudo -E ansible-playbook -c machinectl -i inventory -v archlinux-dokuwiki.yml | ||
+ | </ | ||
+ | After bootstrapping we can enable our mount: | ||
+ | <file - / | ||
+ | [Exec] | ||
+ | PrivateUsers=4587520 | ||
+ | |||
+ | [Files] | ||
+ | PrivateUsersChown=true | ||
+ | Bind=/ | ||
+ | |||
+ | [Network] | ||
+ | Private=yes | ||
+ | VirtualEthernet=yes | ||
+ | </ | ||
+ | <code bash> | ||
+ | machinectl terminate archlinux-dokuwiki | ||
+ | systemctl enable systemd-nspawn@archlinux-dokuwiki.service | ||
+ | systemctl restart systemd-nspawn@archlinux-dokuwiki | ||
+ | </ | ||
+ | ===== Maintainance ===== | ||
+ | Reset child | ||
+ | <code bash> | ||
+ | systemctl stop systemd-nspawn@archlinux-dokuwiki | ||
+ | btrfs subvolume delete / | ||
+ | btrfs subvolume delete / | ||
+ | </ | ||
+ | ===== Todo ===== | ||
+ | * auto update base image, auto reboot childs | ||
+ | * private ethernet | ||
+ | * bind data | ||
+ | |||
+ | ===== Bugs ===== | ||
+ | <file - ~/ | ||
+ | #pid {{ nginx_pidfile }}; | ||
+ | </ | ||
+ | * machine not starting automatically (systemctl enable systemd-nspawn@machine-dokuwiki) | ||
+ | |||
+ | ===== Tips ===== | ||
+ | Iptables forward host port to container | ||
+ | <code bash> | ||
+ | iptables -t nat -A PREROUTING -i ens3 -p tcp --dport 80 -j DNAT --to 10.0.0.10: | ||
+ | </ | ||
+ | Container ip and port can be checked with nmap | ||
+ | <code bash> | ||
+ | nmap -p 80 archlinux-dokuwiki | ||
+ | </ | ||