← 返回命令列表

Linux command

nixos-container 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

List

sudo nixos-container list

Create

sudo nixos-container create [container_name] --config-file [path/to/nix_config_file]

Start, stop, terminate, or destroy

sudo nixos-container [start|stop|terminate|destroy|status] [container_name]

Run a command

sudo nixos-container run [container_name] -- [command] [arguments]

Update

sudo nixos-container update [container_name]

Example

sudo nixos-container root-login [container_name]

说明

nixos-container manages lightweight NixOS containers using Linux namespaces (systemd-nspawn). Each container runs a minimal NixOS system with its own configuration, services, and network namespace. Containers are configured using standard NixOS configuration files, enabling declarative management of containerized services. The container shares the host's kernel but has an isolated filesystem, process tree, and optionally network. Configuration files are stored in /var/lib/container/<name>/etc/nixos/ and can be edited directly before running update to apply changes.

参数

list
List all containers
create _name_
Create a new container
start _name_
Start a stopped container
stop _name_
Stop a running container
terminate _name_
Forcefully terminate a container
destroy _name_
Remove a container and its configuration
status _name_
Show container status
run _name_ -- _command_
Execute a command inside the container
root-login _name_
Open an interactive root shell in the container
update _name_
Rebuild container after configuration changes
--config-file _path_
Nix configuration file for the container

FAQ

What is the nixos-container command used for?

nixos-container manages lightweight NixOS containers using Linux namespaces (systemd-nspawn). Each container runs a minimal NixOS system with its own configuration, services, and network namespace. Containers are configured using standard NixOS configuration files, enabling declarative management of containerized services. The container shares the host's kernel but has an isolated filesystem, process tree, and optionally network. Configuration files are stored in /var/lib/container/<name>/etc/nixos/ and can be edited directly before running update to apply changes.

How do I run a basic nixos-container example?

Run `sudo nixos-container list` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does list do in nixos-container?

List all containers