dockvirt

dockvirt Usage Examples

This directory contains practical examples showing different ways to use dockvirt with the new, simplified API.

πŸ—οΈ How does dockvirt work?

System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      πŸ–₯️  HOST SYSTEM                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  dockvirt CLI                                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚ πŸ“„ config.py β”‚ β”‚ πŸ“₯ image_   β”‚ β”‚ πŸ”§ vm_      β”‚               β”‚
β”‚  β”‚ (config)    β”‚ β”‚ manager.py  β”‚ β”‚ manager.py  β”‚               β”‚
β”‚  β”‚             β”‚ β”‚ (download)  β”‚ β”‚ (create VM) β”‚               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  ~/.dockvirt/                                                   β”‚
β”‚  β”œβ”€β”€ πŸ“‹ config.yaml    (configuration)                         β”‚
β”‚  β”œβ”€β”€ πŸ“ images/        (OS image cache)                        β”‚
β”‚  └── πŸ“ vm_name/       (cloud-init files)                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  πŸ”„ libvirt/KVM                                                 β”‚
β”‚  β”œβ”€β”€ virt-install β†’ creates VM                                 β”‚
β”‚  β”œβ”€β”€ virsh        β†’ manages VM                                 β”‚
β”‚  └── qemu-kvm     β†’ runs VM                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    πŸ–₯️  VIRTUAL MACHINE                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  🐧 Ubuntu/Fedora + cloud-init                                 β”‚
β”‚  β”œβ”€β”€ 🐳 Docker Engine                                          β”‚
β”‚  └── πŸ“¦ docker-compose                                         β”‚
β”‚      β”œβ”€β”€ 🌐 Caddy (reverse proxy :80/:443) ──┐                β”‚
β”‚      └── πŸ“± Your App Container               β”‚                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
                                               β–Ό
                                    🌍 http://app.local

VM Creation Flow

flowchart TD
    A[πŸš€ dockvirt up] --> B{πŸ“‹ config.yaml exists?}
    B -->|❌ No| C[πŸ“ Create default config]
    B -->|βœ… Yes| D[πŸ“– Load configuration]
    C --> D
    
    D --> E{πŸ–ΌοΈ OS image local?}
    E -->|❌ No| F[πŸ“₯ Download from internet]
    E -->|βœ… Yes| G[πŸ’Ύ Use local]
    F --> |⏳ wget/curl| G
    
    G --> H[πŸ”§ Render cloud-init]
    H --> I[πŸ’Ώ Create cloud-init ISO]
    I --> J[πŸ’½ Create VM disk]
    J --> K[⚑ virt-install]
    K --> L[🐳 VM + Docker + Caddy]
    L --> M[🌐 Application available!]
    
    style A fill:#e1f5fe
    style M fill:#c8e6c9
    style F fill:#fff3e0

πŸ†• What’s new?

All examples have been updated to use the latest features:

Tip: Prefer the local repository venv binary to ensure the latest CLI:

# From repository root
make install
source .venv-3.13/bin/activate
dockvirt --help
# Or invoke explicitly without activating:
.venv-3.13/bin/dockvirt --help

πŸ“‹ List of examples

1. Static Nginx Website

flowchart LR
    A[πŸ“ HTML + CSS] --> B[🐳 Docker build]
    B --> C[πŸš€ dockvirt up]
    C --> D[πŸ“₯ Ubuntu download]
    D --> E[⚑ VM creation]
    E --> F[🌐 Nginx serving]
    F --> G[🌍 http://static-site.local]
    
    style A fill:#f9f9f9
    style G fill:#c8e6c9

Example flow:

Developer      Docker         dockvirt       libvirt        Browser
    β”‚              β”‚              β”‚             β”‚              β”‚
    β”œβ”€ build ────→ β”‚              β”‚             β”‚              β”‚
    β”‚              β”œβ”€ nginx:alpine β”‚             β”‚              β”‚  
    β”œβ”€ dockvirt up ───────────────→ β”‚             β”‚              β”‚
    β”‚              β”‚              β”œβ”€ download ──→ β”‚              β”‚
    β”‚              β”‚              β”‚  ubuntu.img   β”‚              β”‚
    β”‚              β”‚              β”œβ”€ virt-install β†’ β”‚              β”‚
    β”‚              β”‚              β”‚             β”œβ”€ VM + Docker  β”‚
    β”‚              β”‚              β”‚             β”œβ”€ Caddy proxy  β”‚
    β”‚              β”‚              β”‚             β”‚              β”‚
    β”œβ”€ add /etc/hosts ────────────────────────────────────────→ β”‚
    β”‚              β”‚              β”‚             β”‚              β”œβ”€ GET /
    β”‚              β”‚              β”‚             β”‚              β”‚

2. Python (Flask) Web Application

flowchart TD
    A[🐍 Python Flask App] --> B[πŸ“‹ requirements.txt]
    B --> C[🐳 Dockerfile]
    C --> D[πŸ”¨ docker build]
    D --> E{πŸ–₯️ Choose OS}
    E -->|Ubuntu| F[🟠 dockvirt up]
    E -->|Fedora| G[πŸ”΅ dockvirt up --os fedora38]
    F --> H[🌐 Flask + Caddy]
    G --> H
    H --> I[🌍 http://flask-app.local]
    
    style A fill:#306998
    style I fill:#c8e6c9

System comparison:

Ubuntu 22.04                     Fedora 38
     β”‚                               β”‚
     β”œβ”€ apt-get update               β”œβ”€ dnf update
     β”œβ”€ install docker               β”œβ”€ install docker
     β”œβ”€ pip install requirements     β”œβ”€ pip install requirements
     β”œβ”€ docker compose up            β”œβ”€ docker compose up
     β”‚                               β”‚
     └─ ~2-3 min startup             └─ ~2-4 min startup

3. Operating System Comparison

flowchart TD
    A[βš™οΈ ~/.dockvirt/config.yaml] --> B{πŸ–₯️ OS Selection}
    B -->|ubuntu22.04| C[🟠 Ubuntu VM]
    B -->|fedora38| D[πŸ”΅ Fedora VM]  
    B -->|debian12| E[🟣 Debian VM]
    B -->|custom| F[βšͺ Custom VM]
    
    C --> G[πŸ“Š Performance Test]
    D --> G
    E --> G
    F --> G
    
    G --> H[πŸ“ˆ Results Comparison]
    
    style A fill:#fff3e0
    style H fill:#c8e6c9

System configuration:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ~/.dockvirt/config.yaml                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ default_os: ubuntu22.04                 β”‚
β”‚ images:                                 β”‚
β”‚   ubuntu22.04:                         β”‚
β”‚     url: https://cloud-images.ubuntu... β”‚
β”‚     variant: ubuntu22.04               β”‚
β”‚   fedora38:                            β”‚
β”‚     url: https://download.fedora...     β”‚ 
β”‚     variant: fedora38       β”‚
β”‚   debian12:     # Your configuration   β”‚
β”‚     url: https://cloud.debian.org...    β”‚
β”‚     variant: debian12                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick start

πŸ” Check system readiness

# Check if all dependencies are installed
dockvirt check

# If something is missing, install automatically
dockvirt setup --install
# Go to any example
cd examples/1-static-nginx-website

# Build the Docker image
docker build -t my-static-website:latest .

# Just run - the parameters are in the .dockvirt file
dockvirt up

Option 2: Traditional CLI parameters

# Run with default Ubuntu 22.04
dockvirt up \
  --name my-test \
  --domain my-test.local \
  --image example-app:latest \
  --port 80

# Or choose Fedora
dockvirt up --os fedora38

πŸ“ Example .dockvirt file

# .dockvirt
name=my-app
domain=my-app.local  
image=my-app:latest
port=80
os=ubuntu22.04

πŸ”§ Requirements

Before running the examples, make sure you have:

πŸ“Š Automatic testing

# Test all examples on different OS
python ../scripts/test_examples.py

# Test only one example
python ../scripts/test_examples.py 1-static-nginx-website

# The test report will be saved in test_results.md

πŸ’‘ Tips

πŸ”Ž Getting the VM IP

dockvirt ip --name <vm_name>

If you test HTTP by IP with Caddy/reverse proxy inside the VM, include a Host header:

curl -H 'Host: app.local' http://<ip>/

πŸ”Œ Networking: NAT vs Bridge (LAN)

By default, libvirt NAT (network=default) is used. To make VMs visible in your LAN, use a Linux bridge (e.g., br0).

sudo nmcli con add type bridge ifname br0 con-name br0
sudo nmcli con add type bridge-slave ifname enp3s0 master br0
sudo nmcli con modify br0 ipv4.method auto ipv6.method auto
sudo nmcli con up br0
dockvirt up --net bridge=br0
net=bridge=br0

With bridge networking, VMs receive a LAN IP and are visible to other machines on your network.

Note: Do not run make or dockvirt with sudo. Tools will request sudo only when necessary and act on your real HOME.

πŸ§ͺ Compatibility testing

The test script checks:

πŸ†˜ Help

If you encounter problems:

  1. Check if libvirt is running: sudo systemctl status libvirtd
  2. Check the VM logs: virsh console <vm-name>
  3. See the configuration: cat ~/.dockvirt/config.yaml
  4. Check the downloaded images: ls -la ~/.dockvirt/images/