lxc-stop
Stop a running LXC container
TLDR
Stop a container
Display help
SYNOPSIS
lxc-stop [-n
PARAMETERS
-n
Specifies the name of the container to stop. This is a mandatory parameter.
-k
Sends SIGKILL to the container immediately. This is a forceful shutdown and may result in data loss or corruption. Avoid using this unless absolutely necessary.
-W
Waits for the container to completely shut down before returning. Otherwise, the command returns immediately after sending the stop signal.
-t
Sets the timeout in seconds before sending SIGKILL if the container hasn't stopped gracefully. The default timeout is usually 30 seconds.
--nokill
Prevents `lxc-stop` from sending SIGKILL to the container after the timeout expires. This is useful for debugging.
DESCRIPTION
The `lxc-stop` command is used to gracefully stop a running Linux container. It sends a SIGTERM signal to the container's init process, allowing the container to shut down cleanly. If the container fails to stop within a reasonable timeout, a SIGKILL signal is sent to forcibly terminate it.
The command interacts with the LXC library to manage the container's lifecycle, ensuring proper cleanup and resource release. It's a crucial tool for managing containerized applications and isolating them from the host system.
CAVEATS
Using the `-k` option can lead to data corruption if the container doesn't have time to cleanly shut down. Always try a graceful stop first. Ensure the container name is accurate to avoid unintended consequences.
RETURN CODES
The command returns 0 on success, and a non-zero value on failure. Common failure reasons include: the container does not exist, insufficient permissions, or the container did not stop within the timeout.
SIGNALS
`lxc-stop` sends SIGTERM initially, followed by SIGKILL if needed. Understanding signal handling in Linux is crucial when working with containers.
HISTORY
The `lxc-stop` command is part of the LXC (Linux Containers) project, which aims to provide an operating-system-level virtualization environment. It has been developed as part of the larger effort to enable lightweight and isolated containerization solutions on Linux systems. The tool has evolved alongside the LXC library, with improvements in signal handling and resource management over time.
SEE ALSO
lxc-start(1), lxc-create(1), lxc-destroy(1), lxc-info(1)