pct-exec
Execute commands within Proxmox containers
TLDR
Launch a command in a container
Open a bash shell in a container
Pass arguments to the command
SYNOPSIS
pct exec <vmid> [OPTIONS] <command> [<args>...]
PARAMETERS
<vmid>
The ID of the Proxmox container (VMID) where the command will be executed.
<command>
The command to be run inside the container. This must be a command available within the container's environment.
<args>...
Optional arguments that are passed to the <command> being executed.
--description <string>
A descriptive string for the executed task, which will be visible in the Proxmox task log.
--no-pty
Disables pseudo-TTY allocation for the command. This is recommended for non-interactive scripts or commands.
--pty
Forces pseudo-TTY allocation for the command. This is useful for interactive commands like shells or text editors where terminal features are expected.
--user <string>
Specifies the username under which the command should be executed inside the container. By default, commands run as 'root'.
--shell <string>
Defines the shell to use when the --user option is specified. If not set, it defaults to /bin/sh.
--timeout <integer>
Sets a timeout in seconds for the command execution. If the command runs longer than this duration, it will be terminated.
--output-format <string>
Specifies the output format for the command's result, e.g., 'json'.
--ignore-lock
Ignores any existing locks on the container. Use with caution as it can lead to inconsistent states if multiple operations are concurrent.
--no-logs
Prevents logging of the command's output in the Proxmox task log. The command's exit status will still be logged.
DESCRIPTION
The pct exec command is a utility provided by the Proxmox Container Toolkit (PCT) for Proxmox Virtual Environment. It allows users to execute commands directly inside a running Linux Container (LXC) managed by Proxmox. Similar in concept to docker exec or lxc-attach, pct exec provides a powerful way to interact with the container's environment, troubleshoot issues, or perform administrative tasks without needing to SSH into the container itself. By default, commands are executed as the root user within the container, but it also supports specifying an alternative user and shell, making it flexible for various use cases, from interactive debugging to automated scripting.
CAVEATS
pct exec is specific to Proxmox Virtual Environment and requires a running LXC container. Commands are executed directly within the container's kernel namespace, granting them full access to the container's resources and file system. Running commands as root inside the container by default carries significant security implications; always ensure commands and their sources are trusted. Network connectivity and overall host system performance can influence command execution within the container.
INTERACTIVE VS. NON-INTERACTIVE USE
When pct exec is used without explicit --pty or --no-pty, it attempts to detect if the command is interactive (e.g., a shell or editor) and allocates a pseudo-TTY accordingly. For scripts or automated tasks, it's best practice to explicitly use --no-pty to avoid issues with terminal control sequences. For commands that require interactive input or display, --pty ensures proper terminal behavior.
EXIT STATUS
The exit status of the pct exec command directly reflects the exit status of the command executed inside the container. A return code of zero typically indicates successful execution, while any non-zero value signifies an error or a specific condition reported by the executed command.
HISTORY
pct exec is an integral part of the Proxmox Container Toolkit (PCT), which was developed to provide robust management capabilities for Linux Containers (LXC) within the Proxmox Virtual Environment (PVE). As PVE evolved into a comprehensive virtualization platform, pct exec was introduced and refined to offer system administrators a direct and efficient way to interact with and troubleshoot running containers, complementing other container management functionalities.
SEE ALSO
pct(1), lxc-attach(1), chroot(8), docker exec(1)