Convert Docker containers to LXC templates compatible with Proxmox VE.
Streamlined workflow: Set your default Proxmox server once, then convert any container with a single command!
# One-time setup
./container2lxc.py --init-config root@your-proxmox.local
# Now just run:
./container2lxc.py nginx:alpine # → Creates template
./container2lxc.py postgres:13 --create-lxc db # → Creates template + LXC container
./container2lxc.py redis:6 --create-lxc cache --start-lxc # → Template + running LXC- Registry Support: Pull directly from Docker Hub, Quay.io, or any container registry
- One-Command Workflow: Set default Proxmox server, then convert containers with single commands
- Automatic Upload: Templates upload directly to Proxmox via SSH/SCP
- Complete Templates: Extract filesystems, generate LXC configs, preserve metadata
- Flexible Output: Save locally or upload to any Proxmox server
- Permission Handling: Robust filesystem extraction with permission issue resolution
- Registry Authentication: Supports private registries with
docker login
- Python 3.7+
- Docker installed and running
- SSH access to Proxmox server (for automatic upload)
- Sufficient disk space for container export and template creation
- Clone or download this repository
- Activate the Python virtual environment:
source venv/bin/activate - Install dependencies (currently none required):
pip install -r requirements.txt
For the best experience, set up a default Proxmox server once:
# Initialize config with your Proxmox server (use 'root' for best compatibility)
./container2lxc.py --init-config root@proxmox.local
# Or with IP address
./container2lxc.py --init-config root@10.0.0.100This creates ~/.container2lxc with your default server. Then simply:
# Pulls nginx:alpine and uploads template to your Proxmox server
./container2lxc.py nginx:alpine
# Pull from Quay.io registry and upload with custom name
./container2lxc.py quay.io/fedora/fedora-minimal:42 -n fedora42
# Any container registry works
./container2lxc.py registry.company.com/myapp:v1.0Convert a Docker container to an LXC template:
# From existing container (uses default Proxmox if configured)
./container2lxc.py <container_id_or_name>
# From registry image (uses default Proxmox if configured)
./container2lxc.py nginx:alpine
# Save to local directory instead of Proxmox
./container2lxc.py nginx:alpine -o /var/templates# Specify a custom template name
./container2lxc.py my_container -n my_custom_template
# Specify output directory
./container2lxc.py nginx:alpine -o /path/to/output
# Upload directly to Proxmox server
./container2lxc.py nginx:alpine -o root@proxmox.local
# Enable verbose logging
./container2lxc.py my_container -v
# Combine options
./container2lxc.py registry.example.com/myapp:v1.0 -n web_server -o root@proxmox.local -vBasic Options:
container: Docker container ID/name or registry URL (required unless using --init-config)-n, --name: Name for the LXC template (defaults to container/image name)-o, --output: Output directory or Proxmox hostname (uses default from config if not specified)-v, --verbose: Enable verbose logging--init-config PROXMOX_HOST: Initialize configuration file with default Proxmox host
LXC Container Creation:
--create-lxc LXC_NAME: Create LXC container with this name after uploading template--lxc-id ID: LXC container ID (auto-assigned if not specified)--lxc-memory MB: Memory for LXC container in MB (default: 1024)--lxc-cores CORES: CPU cores for LXC container (default: 1)--lxc-storage STORAGE: Storage backend for LXC container (default: local-lvm)--start-lxc: Start the LXC container after creation
# Docker Hub images - Create templates only
./container2lxc.py alpine:latest
./container2lxc.py nginx:alpine -n webserver
./container2lxc.py postgres:13 -n database
# Create template + LXC container in one command
./container2lxc.py nginx:alpine --create-lxc webserver
./container2lxc.py postgres:13 --create-lxc database --lxc-memory 2048
./container2lxc.py redis:6-alpine --create-lxc cache --start-lxc
# Quay.io registry with LXC creation
./container2lxc.py quay.io/fedora/fedora-minimal:42 --create-lxc fedora-test
# Private registries (authenticate first with 'docker login')
./container2lxc.py registry.company.com/myapp:latest --create-lxc production
# Advanced LXC configuration
./container2lxc.py ubuntu:20.04 --create-lxc ubuntu-dev \
--lxc-memory 4096 --lxc-cores 4 --lxc-storage local-zfs --start-lxc
# Override default server
./container2lxc.py redis:6-alpine -o root@different-proxmox.com --create-lxc cache
# Save locally instead of uploading (no LXC creation)
./container2lxc.py ubuntu:20.04 -o /var/templates# Convert a running container
docker run -d --name nginx nginx:alpine
./container2lxc.py nginx -n nginx_template
# Convert a stopped container
./container2lxc.py 1a2b3c4d5e6f -n my_app_templateCreate ready-to-use LXC containers in seconds:
# Lightweight containers (great for testing)
./container2lxc.py alpine:latest --create-lxc alpine-test --start-lxc
./container2lxc.py busybox:latest --create-lxc busybox-test --start-lxc
# Application containers
./container2lxc.py nginx:alpine --create-lxc webserver --start-lxc
./container2lxc.py redis:6-alpine --create-lxc cache --lxc-memory 512 --start-lxc
./container2lxc.py postgres:13-alpine --create-lxc database --lxc-memory 2048 --start-lxc
# Development environments
./container2lxc.py ubuntu:20.04 --create-lxc ubuntu-dev \
--lxc-memory 4096 --lxc-cores 4 --start-lxc
./container2lxc.py quay.io/fedora/fedora-minimal:42 --create-lxc fedora-dev \
--lxc-memory 2048 --lxc-cores 2 --start-lxc
# Result: Template uploaded + LXC container created + Container started!
# Access via Proxmox web interface immediatelyWith default server configured, everything happens automatically:
# Just create template
./container2lxc.py nginx:alpine
# ✅ Template created and uploaded to default Proxmox server
# Create template + LXC container
./container2lxc.py nginx:alpine --create-lxc webserver
# ✅ Template created and uploaded to default Proxmox server
# ✅ LXC container 'webserver' created from template
# Access via Proxmox web interface: Node → webserver → Console
# Create template + running LXC container
./container2lxc.py nginx:alpine --create-lxc webserver --start-lxc
# ✅ Template created and uploaded to default Proxmox server
# ✅ LXC container 'webserver' created from template
# ✅ LXC container 'webserver' started
# Your LXC container is ready to use!If saving locally first:
# Save locally
./container2lxc.py alpine:latest -o /var/templates
# Then copy to Proxmox
scp /var/templates/alpine-latest.tar.gz root@proxmox-server:/var/lib/vz/template/cache/- Web Interface: Datacenter → Storage → local → CT Templates
- Create Container: Use the template like any other LXC template
- Template Location:
/var/lib/vz/template/cache/on Proxmox server
The generated template includes:
rootfs/: Complete container filesystemconfig: LXC configuration fileproxmox.conf: Proxmox-specific configurationmetadata.json: Template metadata and Docker container information
The configuration file ~/.container2lxc supports the following options:
[DEFAULT]
proxmox_host = root@your-proxmox-server.local
output_dir = /tmp
template_format = proxmoxproxmox_host: Default Proxmox server for uploadsoutput_dir: Default output directory when not uploading to Proxmoxtemplate_format: Template format (currently only "proxmox" supported)
- Python 3.7+ with standard library (no external dependencies)
- Docker installed and running locally
- SSH access to Proxmox server (for automatic upload)
- Sufficient disk space for container export
- Linux containers only (Windows containers not supported)
- Network configuration may need manual adjustment in LXC
- Some Docker-specific features don't translate to LXC
- Containers are converted to unprivileged LXC by default
- SSH key authentication recommended (or will prompt for password)
- Private registries require
docker loginfirst
- ✅ Docker Hub images (nginx, alpine, postgres, redis, ubuntu)
- ✅ Quay.io registry (fedora-minimal)
- ✅ Container filesystem extraction with permission handling
- ✅ Automatic SSH upload to Proxmox servers
- ✅ Template generation compatible with Proxmox VE
Ensure Docker is installed and running:
docker versionFor private registries, authenticate first:
docker login registry.example.com# Check your current config
cat ~/.container2lxc
# Should show:
# [DEFAULT]
# proxmox_host = root@your-proxmox.local
# output_dir = /tmp
# template_format = proxmox
# Update/fix config
./container2lxc.py --init-config root@correct-proxmox-server.local# Test SSH connection first
ssh root@your-proxmox-server.local
# Set up SSH key if needed
ssh-copy-id root@your-proxmox-server.local
# Check Proxmox template directory exists
ssh root@your-proxmox-server.local "ls -la /var/lib/vz/template/cache/"- Ensure SSH key authentication is set up for Proxmox upload
- Test SSH connection:
ssh root@proxmox.local - Check if SCP is available:
which scp
Make sure the script is executable:
chmod +x container2lxc.py- Verify the template is in
/var/lib/vz/template/cache/ - Check file permissions:
ls -la /var/lib/vz/template/cache/ - Refresh the Proxmox web interface
This project was developed collaboratively with Claude Code (claude.ai/code) in a single session on September 24, 2025. The development process included:
- User requested a Python script to convert Docker containers to LXC templates for Proxmox
- Needed support for container registries and automatic Proxmox upload
Phase 1: Core Functionality
- Created basic
container2lxc.pyscript with Docker export capabilities - Implemented LXC configuration generation
- Added Proxmox template compatibility
- Created proper CLI interface with argparse
Phase 2: Registry & Upload Features
- Added support for pulling containers from registries (Docker Hub, Quay.io, private registries)
- Implemented automatic SCP upload to Proxmox servers
- Added smart detection between container IDs and registry URLs
- Created temporary container handling with automatic cleanup
Phase 3: Configuration & Workflow
- Added
~/.container2lxcconfiguration file support - Implemented default Proxmox server functionality
- Created
--init-configcommand for easy setup - Fixed logic to handle local vs Proxmox output correctly
Phase 4: Testing & Refinement
- Tested with real container images (Alpine, Fedora, nginx)
- Fixed filesystem extraction permission issues
- Resolved SSH authentication and upload logic
- Validated end-to-end workflow from registry to Proxmox
Phase 5: Documentation
- Created comprehensive README with examples
- Updated CLAUDE.md for future Claude Code instances
- Added troubleshooting guides and tested examples
- Zero external dependencies: Uses only Python standard library
- Robust error handling: Handles permission issues, SSH failures, registry errors
- Smart templating: Preserves Docker metadata and environment variables
- Flexible workflow: Supports local storage or direct Proxmox upload
- Registry agnostic: Works with any Docker-compatible registry
- Successfully tested on macOS with Docker Desktop
- Validated with multiple container registries (Docker Hub, Quay.io)
- Confirmed Proxmox upload functionality with SSH key authentication
- Verified template compatibility with Proxmox VE
The project demonstrates Claude Code's capability to create production-ready tools through iterative development, testing, and refinement.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is provided as-is for educational and practical use.