Using pct in Proxmox VE
Proxmox VE (PVE) is a powerful open-source virtualization platform that supports both LXC containers and KVM virtual machines. The pct command line tool is specifically designed to manage LXC containers. Below is a detailed step-by-step guide to help master the pct command.
1. Prerequisites
Before using pct, ensure:

- Necessary OS templates (e.g., Ubuntu, Debian, CentOS) are downloaded from the Proxmox template repository.
2. Basic Commands
2.1 Create a New Container
To create a new LXC container, use the pct create command.
| |
Example:
| |
Explanation:
100: The unique ID for the container.local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.gz: The OS template to use.--storage local-lvm: The storage where the container will be created.--rootfs 8G: Allocate 8GB of disk space for the root filesystem.--hostname LXC-100: Set the hostname for the container.--memory 1024: Allocate 1024MB of RAM.--cores 1: Assign 1 CPU core.--net0: Configure the network interface (DHCP in this case).
2.2 Start a Container
To start a container, use the pct start command.
| |
Example:
| |
2.3 Stop a Container
To stop a running container, use the pct stop command.
| |
Example:
| |
2.4 Restart a Container
To restart a container, use the pct restart command.
| |
Example:
| |
2.5 Access the Container’s Shell
To access the container’s shell, use the pct enter command.
| |
Example:
| |
2.6 List All Containers
To list all containers on the node, use the pct list command.
| |
Output Example:
| |
2.7 Modify Container Configuration
To modify a container’s configuration, use the pct set command.
| |
Example (Increase Memory Limit):
| |
Example (Add a Mount Point):
| |
2.8 Clone a Container
To clone an existing container, use the pct clone command.
| |
Example:
| |
2.9 Backup a Container
To create a backup of a container, use the vzdump command.
Example:

Backup Container ID 302 (Stopped Mode)
| |
Backup Container ID 101 (Snapshot Mode)
| |
--compress: gzip (standard), lzo (fast), zstd (best balance)
--mode:
stop(service interruption, maximum consistency)snapshot(live backup, requires supported filesystem)
--storage: Target storage ID (view with pvesm list)
Multi LXC Backup
| |
2.10 Restore a Container
To restore a container from a backup, use the pct restore command.
| |
Example:
| |
2.11 Destroy a Container
To permanently delete a container.
| |
<vmid>: The ID of the container to be destroyed.--purge: Removes all associated data, including backups and configuration files.
Example:
| |
3. Advanced Usage
3.1 Mount Host Directories
Directories from the host can be mounted into the container.
Example:
| |
3.2 Configure Networking
Static IPs or additional network interfaces can be configured.
Example (Static IP):
| |
Set VLAN
Static IP Example:
| |
- Sets the VLAN tag to
10for theeth0interface.- Connects the interface to the
vmbr0bridge.- Assigns a static IP address
192.168.10.100/24and gateway192.168.10.1.
DHCP Example:
| |
- Multiple network interfaces can be configured by incrementing the
--netXoption (e.g.,--net1,--net2).- Ensure the VLAN is properly configured on the Proxmox host’s network bridge (e.g.,
vmbr0orvmbr1).
3.3 Resource Limits
CPU and memory limits can be set for the container.
Example:
| |
4. Troubleshooting
- Container Fails to Start: Check logs using
pct logs <vmid>. - Network Issues: Verify the network configuration with
pct config <vmid>.
5. Help and Documentation
- Use
pct helpto see a list of available commands. - For detailed documentation, use
man pct.
6. Automate to creation of an LXC container in Proxmox VE (PVE).
Script Overview
- Prompts the user for input (LXC ID and password).
- Checks if the LXC ID already exists and handles conflicts.
- Downloads the LXC template if it doesn’t already exist.
- Creates a new LXC container with specified configurations.
- Appends additional configuration to the container’s configuration file.
| |
7. Initialization of the environment when deploying a custom LXC.
Script Overview
- Install packages:
git,wget,curl,tree,iperf3,vim,tmux - Add a user
- Enable tab completion
- Retrieve public key from GitHub
- Install VIM-PLUG
- Configure tmux
- Exit
| |
Conclusion
The pct command line tool is a powerful way to manage LXC containers in Proxmox VE. With this guide, creating, configuring, and managing containers efficiently should be straightforward. For further questions or assistance, additional resources are available in the Proxmox documentation.
