Options (4)
-D, --directorybooleanRun a command in a container
Example:
systemd-nspawn {{[-D|--directory]}} {{path/to/container_root}}-b, --bootbooleanRun a full Linux-based OS in a container
Example:
systemd-nspawn {{[-b|--boot]}} {{[-D|--directory]}} {{path/to/container_root}}-a, --as-pid2booleanRun 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, --machinebooleanSpecify 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_rootRun a full Linux-based OS in a container
systemd-nspawn [-b|--boot] [-D|--directory] path/to/container_rootRun 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_rootmade by @shridhargupta | data from tldr-pages