ImageBuilder automates the creation of VM images with SSH server pre-configured. It uses Docker to build minimal Alpine or Debian-based rootfs images, complete with networking and a custom init script.
Constructor
ImageBuilder(cache_dir=None)
Initialize the image builder.
Directory to store built images. If not specified, defaults to
~/.smolvm/images/.Methods
check_docker()
Check if Docker is installed and the daemon is reachable.
Returns
True if Docker is available and the daemon responds, False otherwise.docker_requirement_error()
Create a diagnostic ImageError with a specific message based on what is wrong with Docker. This method inspects the Docker installation and returns a targeted error that tells the user exactly how to fix the problem.
The method distinguishes between these scenarios:
- Docker not installed — prompts to install Docker Desktop or
docker.io - Daemon not running — prompts to start Docker Desktop or the Docker service
- Permission denied on socket — prompts to grant access to
/var/run/docker.sock - Daemon timeout — reports that Docker is not responding
- Other errors — includes the original Docker error output for debugging
An
ImageError with a human-readable message describing the problem and how to fix it.You don’t need to call this method directly in most cases. All build methods (
build_alpine_ssh, build_alpine_ssh_key, build_debian_ssh_key) automatically call it and raise the resulting ImageError when Docker is unavailable.build_alpine_ssh(name, ssh_password, rootfs_size_mb, kernel_url)
Build an Alpine Linux image with SSH server configured for password authentication.
Uses Docker to create a minimal Alpine Linux rootfs with:
- OpenSSH server configured and auto-starting
- Root password authentication
- Custom
/initscript that sets up networking and starts sshd - DNS resolution configured
boot_args containing init=/init so the custom init script runs. Use the SSH_BOOT_ARGS constant for convenience.
Image name for caching. Images are stored in
{cache_dir}/{name}/.Root password for SSH authentication.
Size of rootfs in megabytes.
Optional kernel URL override. If not provided, downloads a Firecracker-compatible kernel for the host architecture.
Tuple of
(kernel_path, rootfs_path) pointing to the built image files.ImageError- If Docker is not available or build fails
build_alpine_ssh_key(ssh_public_key, name, rootfs_size_mb, kernel_url)
Build an Alpine Linux image with key-only SSH access (no password authentication).
Public key content (string starting with “ssh-”) or path to a public key file.
Image name for caching.
Size of rootfs in megabytes.
Optional kernel URL override.
Tuple of
(kernel_path, rootfs_path).ImageError- If Docker is not available, build fails, or SSH key format is invalid
build_debian_ssh_key(ssh_public_key, name, rootfs_size_mb, base_image, kernel_url)
Build a Debian Linux image with key-only SSH access.
This method creates a larger, more feature-complete image based on Debian. It’s suitable for applications that need a full Linux environment with standard utilities.
Public key content (string starting with “ssh-”) or path to a public key file.
Image name for caching.
Size of rootfs in megabytes. Debian images require more space than Alpine.
Docker base image to build from.
Optional kernel URL override.
Tuple of
(kernel_path, rootfs_path).ImageError- If Docker is not available, build fails, or SSH key format is invalid
Constants
SSH_BOOT_ARGS
Default boot arguments for VMs built with SSH support.
console=ttyS0- Serial console outputreboot=k- Reboot via keyboard controllerpanic=1- Reboot 1 second after kernel panicpci=off- Disable PCI bus scanning (not needed in microVMs)root=/dev/vda- Root filesystem devicerw- Mount root as read-writeinit=/init- Use custom init script at/init
init=/init parameter is required for SSH-enabled images to work properly. The custom init script handles:
- Mounting essential filesystems (
/proc,/sys,/dev) - Configuring networking from kernel command line
- Setting up DNS resolution
- Starting the SSH daemon
- Signal handling for clean shutdown
Image Caching
All built images are cached to avoid rebuilding. For key-based images (build_alpine_ssh_key and build_debian_ssh_key), the cache is invalidated and rebuilt if the SSH key file is newer than the cached image.
Related
- ImageManager - Download and cache pre-built images
- ImageSource - Define downloadable image metadata
- VMConfig - Configure VM instances