How to Manage LXC Containers with the pct Command in Proxmox


Managing LXC Containers with the pct Command in Proxmox

Proxmox Virtual Environment (PVE) provides a powerful command-line tool called pct that allows you to manage LXC (Linux Containers) efficiently. This guide will cover the most important commands to help you get started with container management in Proxmox.

Overview of pct

The pct command is a command-line utility designed specifically for managing LXC containers in Proxmox. With it, you can perform a variety of tasks, including creating, starting, stopping, and configuring containers.

For more detailed information, you can refer to the documentation here.

Key Commands

1. List All Containers

To view all your existing containers, use the following command:

pct list

This will display a list of containers along with their IDs and current statuses.

2. Start, Stop, or Reboot a Container

You can control the operational state of a specific container with these commands. Replace 100 with your container ID:

  • Start a container:

    pct start 100
  • Stop a container:

    pct stop 100
  • Reboot a container:

    pct reboot 100

3. Access Container’s Shell

To enter the shell of a specific container for management or troubleshooting, use:

pct enter 100

4. Create a Container from a Template

To create a new container from an existing template, you can run:

pct create 100 /var/lib/vz/template/cache/distro-name.tar.zst -hostname hostname -password password --rootfs local-lvm --on-boot

Make sure to adjust the parameters such as the ID, distro name, hostname, and password as required.

5. Resize Container Disk

To resize the disk of a container (e.g., to 20 GB), use:

pct resize 100 rootfs 20G

You can replace rootfs with the appropriate mount point if needed.

6. Show Container Configuration

To display the configuration details of a specific container, use:

pct config 100

This will provide you with information such as network settings, resources allocated, and more.

7. Snapshot a Container

To create a snapshot of a container for backup or recovery purposes, use the following command:

pct snapshot 100 my-snapshot --description "My snapshot description"

This allows for easy restoration to a previous state.

8. Destroy a Container

To permanently delete a container and remove all related resources, execute:

pct destroy 100 --purge

This operation is irreversible, so be certain you want to proceed.

Conclusion

The pct command is essential for managing LXC containers in Proxmox. From creating and configuring containers to handling snapshots and deletions, this command provides a robust set of tools for effective container management. For further reading and more advanced options, check out the Proxmox documentation. Happy container management!

See Also