commands.sh

systemd-nspawn

linux

Spawn a command or OS in a lightweight container.

More info →

Options (4)

-D, --directoryboolean

Run a command in a container

Example: systemd-nspawn {{[-D|--directory]}} {{path/to/container_root}}
-b, --bootboolean

Run a full Linux-based OS in a container

Example: systemd-nspawn {{[-b|--boot]}} {{[-D|--directory]}} {{path/to/container_root}}
-a, --as-pid2boolean

Run the specified command as PID 2 in the container (as opposed to PID 1) using a stub init process

Example: systemd-nspawn {{[-D|--directory]}} {{path/to/container_root}} {{[-a|--as-pid2]}}
-M, --machineboolean

Specify the machine name and hostname

Example: systemd-nspawn {{[-M|--machine]}} {{container_name}} --hostname {{container_host}} {{[-D|--directory]}} {{path/to/container_root}}

Examples (4)

Run a command in a container

systemd-nspawn [-D|--directory] path/to/container_root

Run a full Linux-based OS in a container

systemd-nspawn [-b|--boot] [-D|--directory] path/to/container_root

Run the specified command as PID 2 in the container (as opposed to PID 1) using a stub init process

systemd-nspawn [-D|--directory] path/to/container_root [-a|--as-pid2]

Specify the machine name and hostname

systemd-nspawn [-M|--machine] container_name --hostname container_host [-D|--directory] path/to/container_root
made by @shridhargupta | data from tldr-pages