LinuxCommandLibrary

lxc-destroy

Delete an existing LXC container

TLDR

Delete a container

$ sudo lxc-destroy [container_name]
copy

Display help
$ lxc-destroy [[-?|--help]]
copy

SYNOPSIS

lxc-destroy {-n name} [-f]
lxc-destroy [--help | --version]

PARAMETERS

-n name, --name name
    Specifies the name of the LXC container to be destroyed. This option is mandatory.

-f, --force
    Forces the destruction of the container even if it is currently running. The command will attempt to stop the container before deleting it.

-h, --help
    Displays a help message and exits.

-v, --version
    Shows the version information and exits.

DESCRIPTION

The lxc-destroy command is used to permanently delete an LXC (Linux Container) instance from the system. When a container is destroyed, its entire root filesystem, configuration files, and any associated data are completely removed. This is an irreversible operation, and all data within the container will be lost. Before destruction, it's generally recommended that the container be stopped. If the container is still running and the -f or --force option is provided, lxc-destroy will first attempt to stop the container gracefully before proceeding with the deletion. This command is a critical part of managing the lifecycle of LXC containers, complementing lxc-create for container provisioning. It requires root privileges or sudo to execute successfully.

CAVEATS

This is an irreversible and destructive operation. All data within the specified container will be permanently lost.
Ensure the correct container name is provided to avoid accidental data loss.
The command typically requires root privileges or sudo to execute.

USAGE EXAMPLE

To destroy a container named "mycontainer", ensure it is stopped first or use the --force flag:
sudo lxc-stop -n mycontainer
sudo lxc-destroy -n mycontainer

To force destroy a running container:
sudo lxc-destroy -n mycontainer --force

PERMISSIONS

Executing lxc-destroy typically requires superuser privileges (root or sudo). Without sufficient permissions, the command will fail with an error indicating permission denied or that the container does not exist.

HISTORY

lxc-destroy has been a fundamental command within the LXC project since its early days (around 2008-2009). As a core utility, its development has closely tracked the evolution of the LXC container runtime, providing a crucial mechanism for cleaning up and removing containers after their utility has expired, or to free up system resources. Its design emphasizes simplicity and direct action, reflecting the core philosophy of the LXC toolset.

SEE ALSO

lxc(7), lxc-create(1), lxc-start(1), lxc-stop(1), lxc-ls(1), lxc-info(1)

Copied to clipboard