lxc-ls
List existing LXC containers
TLDR
List all containers
List active containers (including frozen and running)
List only frozen containers
List only stopped containers
List containers in a fancy, column-based output
Display help
SYNOPSIS
lxc-ls [options]
This command lists LXC containers and their attributes. Options allow for filtering by state, custom output formats, and specifying container paths.
PARAMETERS
-a, --all
List all containers, including those that are stopped or frozen. This is the default behavior.
-s, --stopped
Only list containers that are currently in the STOPPED state.
-r, --running
Only list containers that are currently in the RUNNING state.
-f, --fast
Perform a fast listing. This option avoids querying the actual state of each container, making the command execute faster, especially with a large number of containers.
-P, --lxcpath <path>
Specify an alternative LXC path from which to list containers. By default, it uses the system-wide LXC path.
-F, --defined-path <path>
Only show containers that are defined at the specified path, typically used within an LXC path.
-c, --config <file>
Use an alternative configuration file for LXC operations instead of the default.
-n, --name <name>
Show details specifically for the container with the given name.
-L, --list-options
List all available output field options that can be used with the -o
(--output
) parameter.
-p, --print-defined-path
Print the path where the container is defined, in addition to other details.
-o, --output <field>[,<field>...]
Specify a comma-separated list of fields to output. Common fields include name, state, ipv4, pid, and autostart.
-H, --no-headers
Do not print the header line when listing container information, useful for scripting.
-h, --help
Display a help message and exit.
-v, --version
Print the LXC version information and exit.
DESCRIPTION
The lxc-ls
command is a fundamental utility within the Linux Containers (LXC) framework, designed to enumerate and display information about existing LXC containers on a system. It provides a quick overview of which containers are defined, their current states (running, stopped, frozen, etc.), and other relevant details such as their IP addresses or unique identifiers.
By default, lxc-ls
lists all containers. However, it offers various options to filter the output, allowing users to view only running containers, stopped containers, or to customize the displayed fields for more specific information. This command is crucial for container management, helping administrators and users quickly assess the container landscape and the operational status of their LXC environments.
CAVEATS
lxc-ls
is designed to interact specifically with containers managed by the LXC runtime. It will not list containers managed by other containerization technologies like Docker, Podman, or Kubernetes.- By default or when filtering by state (e.g.,
-s
,-r
),lxc-ls
queries the state of each container, which can introduce a slight delay for a large number of containers. The-f
(--fast
) option can be used to skip state checks and speed up listing.
COMMON OUTPUT FIELDS FOR <CODE>-O</CODE>
When using the -o
(--output
) option, you can specify various fields to display. Common and useful fields include:
name
: The name of the container.state
: The current operational state (e.g., RUNNING, STOPPED, FROZEN).ipv4
: The primary IPv4 address assigned to the container.ipv6
: The primary IPv6 address assigned to the container.pid
: The process ID of the container's init process.autostart
: Indicates if the container is configured to autostart.uuid
: The unique identifier of the container.path
: The path where the container's configuration is defined.
You can get a full list of supported fields by running lxc-ls -L
.
FILTERING CONTAINERS
While lxc-ls
lists all containers by default, you can easily filter them using specific options:
lxc-ls -r
...will only list containers that are currently in the RUNNING state.
lxc-ls -s
...will only list containers that are currently in the STOPPED state.
HISTORY
The lxc-ls
command has been an integral part of the LXC project since its early days, evolving alongside the container technology itself. As a core utility, its development has focused on providing efficient and flexible ways to query the status of containers, adapting to new features and performance requirements of the LXC ecosystem. It is a fundamental tool for managing and overseeing LXC environments.
SEE ALSO
lxc(7), lxc-create(1), lxc-start(1), lxc-stop(1), lxc-info(1), lxc-attach(1)