Senior LevelLinux Commands & SysAdmin
What is systemd-nspawn and how does it launch lightweight OS container namespaces?
❓ Interview Prompt: Explain systemd-nspawn, namespace container isolation, booting full systemd init inside containers, and local testing.
'systemd-nspawn' is a container tool built directly into systemd that launches namespace-isolated process trees from root directory trees:
Advantages over Docker:
•
Boots a full, real systemd init process inside the container namespace.
•
Ideal for testing complete OS distributions, building packages, and testing systemd service units without running heavy VMs.
Code Implementation Example
bash
# Bootstrap minimal Debian rootfs using debootstrap
sudo debootstrap bookworm /var/lib/machines/debian-container
# Launch interactive systemd-nspawn container
sudo systemd-nspawn -D /var/lib/machines/debian-container --boot💡Booting lightweight OS containers using systemd-nspawn.
🎯 Interview Key Takeaway
Use systemd-nspawn to launch lightweight OS containers with full systemd init trees for local testing.
#systemd-nspawn#Containers#Namespaces#Senior
Back to all Linux Commands & SysAdmin Questions→