← 返回命令列表

Linux command

systemd-nspawn 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run

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

Run

systemd-nspawn -b -D [path/to/container_root]

Run

systemd-nspawn -D [path/to/container_root] -a

Specify

systemd-nspawn -M [container_name] --hostname [hostname] -D [path/to/container_root]

说明

systemd-nspawn spawns a command or full operating system in a lightweight container. It uses Linux namespaces and cgroups for isolation but is simpler than full container solutions like Docker. The tool is useful for testing, building packages, and running isolated services. With --boot, it can run a complete init system, making it suitable for system containers.

参数

-D, --directory _path_
Root directory of the container
-b, --boot
Boot the container's init system
-M, --machine _name_
Set the machine name
-a, --as-pid2
Run command as PID 2 with stub init
--hostname _name_
Set the container hostname
-u, --user _user_
Run as specified user
--bind _src:dest_
Bind mount host path into container
-n, --network-veth
Create a virtual Ethernet link
--private-network
Disconnect from host network

FAQ

What is the systemd-nspawn command used for?

systemd-nspawn spawns a command or full operating system in a lightweight container. It uses Linux namespaces and cgroups for isolation but is simpler than full container solutions like Docker. The tool is useful for testing, building packages, and running isolated services. With --boot, it can run a complete init system, making it suitable for system containers.

How do I run a basic systemd-nspawn example?

Run `systemd-nspawn -D [path/to/container_root]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -D, --directory _path_ do in systemd-nspawn?

Root directory of the container