### Install and Start Colima Source: https://github.com/abiosoft/colima/blob/main/skills/SKILL.md Initial setup using Homebrew and starting the default VM instance. ```sh brew install colima # + docker client if using Docker runtime: brew install docker colima start # boots the VM, Docker runtime by default docker run hello-world # docker client works with no extra setup ``` -------------------------------- ### Setup() error Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Installs or updates the runner. Call CheckSetup() first to determine if setup is needed. ```APIDOC ## Setup() error ### Description Installs or updates the runner. Call CheckSetup() first to determine if setup is needed. ### Returns - **error** - Nil if setup/update succeeds ``` -------------------------------- ### Initialize Colima Configuration in Go Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/config.md Demonstrates basic setup of a Colima configuration and starting an application instance. ```go package main import ( "log" "github.com/abiosoft/colima/config" "github.com/abiosoft/colima/app" ) func main() { // Create a Docker instance with 4 CPUs and 8 GiB memory conf := config.Config{ CPU: 4, Memory: 8, Disk: 100, Runtime: "docker", } a, _ := app.New() if err := a.Start(conf); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Perform runner setup with Go Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Installs or updates the runner. It is recommended to verify the need for setup using CheckSetup first. ```go runner, _ := model.GetRunner(model.RunnerRamalama) status, _ := runner.CheckSetup() if status.NeedsSetup { if err := runner.Setup(); err != nil { log.Fatalf("Setup failed: %v\n", err) } log.Println("Setup completed") } ``` -------------------------------- ### GuestActions Usage Example Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/environment.md Demonstrates initializing a Lima VM, starting it with configuration, running commands, and checking status. ```go import ( "context" "github.com/abiosoft/colima/environment/vm/lima" "github.com/abiosoft/colima/environment/host" "github.com/abiosoft/colima/config" ) guest := lima.New(host.New()) // Start the VM conf := config.Config{CPU: 4, Memory: 8, Disk: 100} ctx := context.Background() if err := guest.Start(ctx, conf); err != nil { log.Fatal(err) } // Run a command in the VM if err := guest.Run("docker", "--version"); err != nil { log.Fatal(err) } // Get VM information if running := guest.Running(ctx); running { log.Println("VM is running") } arch := guest.Arch() log.Printf("VM architecture: %s\n", arch) ``` -------------------------------- ### Container Runtime Usage Example Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/environment.md Demonstrates creating, provisioning, starting, and stopping a Docker container runtime. ```go import ( "context" "github.com/abiosoft/colima/environment" "github.com/abiosoft/colima/environment/host" "github.com/abiosoft/colima/environment/vm/lima" ) host := host.New() guest := lima.New(host) // Create a Docker runtime docker, err := environment.NewContainer("docker", host, guest) if err != nil { log.Fatal(err) } ctx := context.Background() // Provision (install) Docker if err := docker.Provision(ctx); err != nil { log.Fatal(err) } // Start Docker if err := docker.Start(ctx); err != nil { log.Fatal(err) } // Get version version := docker.Version(ctx) log.Printf("Docker version: %s\n", version) // Stop Docker if err := docker.Stop(ctx, false); err != nil { log.Fatal(err) } ``` -------------------------------- ### Start(config.Config) Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/app.md Starts the VM and provisions the specified container runtime. ```APIDOC ## Start(config.Config) ### Description Starts the VM and provisions the specified container runtime(s). Includes optional Kubernetes setup. Fails if an instance is already running under the current profile. ### Signature `func (c colimaApp) Start(conf config.Config) error` ### Parameters - **conf** (config.Config) - Required - VM and runtime configuration ### Returns - **error** - Nil on success; error if startup fails at any stage ``` -------------------------------- ### ValidateConfig Usage Examples Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/configmanager.md Examples demonstrating how to validate configurations during standard startup and after user edits. ```go conf, _ := configmanager.Load() if err := configmanager.ValidateConfig(conf); err != nil { log.Fatalf("Config validation failed: %v\n", err) } // Proceed with validated config app, _ := app.New() app.Start(conf) ``` ```go // User edits config with --edit flag conf, _ := configmanager.LoadFrom(tempEditFile) if err := configmanager.ValidateConfig(conf); err != nil { log.Printf("Invalid configuration: %v\n", err) log.Println("Fix the configuration and try again") return } // Config is valid, proceed ``` -------------------------------- ### Start Colima Instance Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/app.md Configures and starts the VM with specific runtime and Kubernetes settings. ```go conf := config.Config{ CPU: 2, Memory: 4, Disk: 50, Runtime: "docker", Kubernetes: config.Kubernetes{ Enabled: true, Version: "v1.28.0", }, } if err := app.Start(conf); err != nil { log.Fatal(err) } ``` -------------------------------- ### Example: Enable x86 Containers on Apple Silicon Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/core.md Usage example for setting up binfmt to support cross-architecture containers. ```go package main import ( "log" "github.com/abiosoft/colima/core" "github.com/abiosoft/colima/environment" "github.com/abiosoft/colima/environment/host" "github.com/abiosoft/colima/environment/vm/lima" ) func main() { hostEnv := host.New() guestEnv := lima.New(hostEnv) // Enable x86 container support on Apple Silicon VM if err := core.SetupBinfmt(hostEnv, guestEnv, environment.AARCH64); err != nil { log.Fatalf("Failed to setup binfmt: %v\n", err) } log.Println("binfmt setup complete") } ``` -------------------------------- ### Start Colima with a Custom Profile Source: https://github.com/abiosoft/colima/blob/main/docs/FAQ.md Use a separate profile to test configurations without affecting the default setup. ```sh colima start debug ``` -------------------------------- ### Edit and Start Instance Source: https://github.com/abiosoft/colima/blob/main/skills/references/configuration.md Opens the configuration file for editing and starts the instance in one command. ```sh colima start --edit # edit + start (one-off) ``` -------------------------------- ### Installing Docker Buildx Plugin Source: https://github.com/abiosoft/colima/blob/main/skills/references/runtimes.md Manual installation of the buildx plugin for Docker. ```sh brew install docker-buildx mkdir -p ~/.docker/cli-plugins ln -sfn $(which docker-buildx) ~/.docker/cli-plugins/docker-buildx docker buildx version ``` -------------------------------- ### Start Colima with Incus Runtime Source: https://github.com/abiosoft/colima/blob/main/README.md Starts Colima using the Incus runtime. Requires the Incus client to be installed. Note: VM support on Incus requires specific hardware. ```bash colima start --runtime incus incus launch images:alpine/edge incus list ``` -------------------------------- ### CheckSetup() (SetupStatus, error) Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Checks if the runner needs setup or updates. Should be called before Setup() to display version info. ```APIDOC ## CheckSetup() (SetupStatus, error) ### Description Checks if the runner needs setup or updates. Should be called before Setup() to display version info. ### Returns - **SetupStatus** - Current and available version info - **error** - Error if version check fails ``` -------------------------------- ### Starting and Using Kubernetes Source: https://github.com/abiosoft/colima/blob/main/skills/references/runtimes.md Usage for the Kubernetes runtime. ```sh colima start --kubernetes # needs kubectl (brew install kubectl) kubectl run caddy --image=caddy kubectl get pods ``` -------------------------------- ### Get Host Architecture Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/core.md Function signature and usage example for determining host CPU architecture. ```go func HostArch() Arch ``` ```go hostArch := environment.HostArch() if hostArch == environment.AARCH64 { // Running on Apple Silicon // Enable x86 container support } ``` -------------------------------- ### Start Colima with Docker Runtime Source: https://github.com/abiosoft/colima/blob/main/README.md Initiates Colima using the Docker runtime. Ensure the Docker client is installed and accessible. ```bash colima start docker run hello-world docker ps ``` -------------------------------- ### Start Colima with Kubernetes Enabled Source: https://github.com/abiosoft/colima/blob/main/README.md Enables Kubernetes on Colima. Requires `kubectl` to be installed. Use `kubectl` commands to interact with the cluster. ```bash colima start --kubernetes kubectl run caddy --image=caddy kubectl get pods ``` -------------------------------- ### Check runner setup status with Go Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Determines if the runner requires an update or initial setup. Call this before invoking the Setup method. ```go runner, _ := model.GetRunner(model.RunnerRamalama) status, err := runner.CheckSetup() if err != nil { log.Fatalf("Failed to check setup: %v\n", err) } if status.NeedsSetup { log.Printf("Update available: %s → %s\n", status.CurrentVersion, status.LatestVersion) } else { log.Printf("Already up-to-date: %s\n", status.CurrentVersion) } ``` -------------------------------- ### Setup Binfmt Support Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/core.md Function signature for configuring binary format support in the VM. ```go func SetupBinfmt(host hostActions, guest guestActions, arch environment.Arch) error ``` -------------------------------- ### Basic usage of the App interface Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/app.md Demonstrates checking the status of an instance and starting it with default configuration. ```go package main import ( "log" "github.com/abiosoft/colima/app" "github.com/abiosoft/colima/config" ) func main() { a, err := app.New() if err != nil { log.Fatal(err) } // Check if already running if a.Active() { log.Println("Colima is already running") return } // Start with default configuration conf := config.Config{} if err := a.Start(conf); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Define SetupStatus Struct Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Represents the installation and update status of a runner. ```go type SetupStatus struct { // NeedsSetup indicates whether setup/update is required. NeedsSetup bool // CurrentVersion is the currently installed version (empty if not installed). CurrentVersion string // LatestVersion is the latest available version (empty if not checked). LatestVersion string } ``` -------------------------------- ### Example: Verify Lima Version Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/core.md Usage example for checking Lima version compatibility. ```go package main import ( "log" "github.com/abiosoft/colima/core" ) func main() { if err := core.LimaVersionSupported(); err != nil { log.Fatalf("Lima compatibility error: %v\n", err) } log.Println("Lima version is compatible") } ``` -------------------------------- ### Start Colima with Defaults Source: https://github.com/abiosoft/colima/blob/main/README.md Use this command to start Colima with its default configuration. No specific runtime or settings are required. ```bash colima start ``` -------------------------------- ### Configure Volume Mounts Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/config.md Example of defining a slice of mount configurations. ```go mounts := []config.Mount{ {Location: "/Users/alice/projects", MountPoint: "/workspace", Writable: true}, {Location: "/var/log", Writable: false}, } ``` -------------------------------- ### Configure Kubernetes Settings Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/config.md Example of enabling Kubernetes with specific K3s arguments. ```go kubernetes := config.Kubernetes{ Enabled: true, Version: "v1.28.0", K3sArgs: []string{ "--disable=traefik,local-storage,metrics-server", "--default-local-storage-path=/opt/k3s-storage", }, } ``` -------------------------------- ### Starting and Using Docker Runtime Source: https://github.com/abiosoft/colima/blob/main/skills/references/runtimes.md Standard usage for the default Docker runtime. ```sh colima start # docker runtime docker run hello-world docker ps ``` -------------------------------- ### Install Colima with Nix Source: https://github.com/abiosoft/colima/blob/main/README.md Use this command to install Colima via Nix. ```shell nix-env -iA nixpkgs.colima ``` -------------------------------- ### Binary - Install Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Installs the downloaded Colima binary into the system's PATH. ```sh # install in $PATH sudo install colima-$(uname)-$(uname -m) /usr/local/bin/colima ``` -------------------------------- ### Start Colima with Containerd Runtime Source: https://github.com/abiosoft/colima/blob/main/README.md Starts Colima with the Containerd runtime. Use `colima nerdctl` to interact with Containerd. ```bash colima start --runtime containerd nerdctl run hello-world nerdctl ps ``` -------------------------------- ### Install Colima with Mise Source: https://github.com/abiosoft/colima/blob/main/README.md Use this command to install Colima via Mise. ```shell mise use -g colima@latest ``` -------------------------------- ### Define Provisioning Scripts Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/config.md Defines the structure for provisioning scripts and provides an example of configuring multiple boot-time tasks. ```go type Provision struct { Mode string `yaml:"mode"` Script string `yaml:"script"` } ``` ```go provisions := []config.Provision{ { Mode: "after-boot", Script: "sudo apt-get update && sudo apt-get install -y git", }, { Mode: "ready", Script: "docker pull ubuntu:latest", }, } ``` -------------------------------- ### Starting and Using Containerd Runtime Source: https://github.com/abiosoft/colima/blob/main/skills/references/runtimes.md Usage for the containerd runtime with nerdctl. ```sh colima start --runtime containerd colima nerdctl install # add a `nerdctl` alias to $PATH (recommended) nerdctl run hello-world nerdctl ps ``` -------------------------------- ### Install Colima with Homebrew Source: https://github.com/abiosoft/colima/blob/main/README.md Use this command to install Colima via Homebrew. ```shell brew install colima ``` -------------------------------- ### Install Docker Buildx plugin Source: https://github.com/abiosoft/colima/blob/main/docs/FAQ.md Install the Docker Buildx plugin via Homebrew or by manually downloading the binary to the CLI plugins directory. ```bash brew install docker-buildx # Follow the caveats mentioned in the install instructions: # mkdir -p ~/.docker/cli-plugins # ln -sfn $(which docker-buildx) ~/.docker/cli-plugins/docker-buildx docker buildx version # verify installation ``` ```bash ARCH=amd64 # change to 'arm64' for m1 VERSION=v0.11.2 curl -LO https://github.com/docker/buildx/releases/download/${VERSION}/buildx-${VERSION}.darwin-${ARCH} mkdir -p ~/.docker/cli-plugins mv buildx-${VERSION}.darwin-${ARCH} ~/.docker/cli-plugins/docker-buildx chmod +x ~/.docker/cli-plugins/docker-buildx docker buildx version # verify installation ``` -------------------------------- ### Setup and Run AI Models Source: https://github.com/abiosoft/colima/blob/main/docs/FAQ.md Commands to prepare the environment and execute specific AI models. ```sh colima model setup colima model run gemma3 ``` -------------------------------- ### Configure VM Network Settings Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/config.md Example of setting up bridged networking with custom DNS resolvers and hosts. ```go conf := config.Config{ Network: config.Network{ Address: true, Mode: "bridged", BridgeInterface: "en0", DNSResolvers: []net.IP{ net.ParseIP("8.8.8.8"), net.ParseIP("1.1.1.1"), }, DNSHosts: map[string]string{ "myapp.local": "192.168.1.100", }, }, } ``` -------------------------------- ### Implement CLI Edit Workflow Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/configmanager.md Illustrates the logic for the start --edit command, involving loading, external editing, validation, and application restart. ```go // User runs: colima start --edit // 1. Load current or default config conf, _ := configmanager.Load() // 2. Open in editor (user edits) editedFile := openEditor(conf) // 3. Load edited version conf, err := configmanager.LoadFrom(editedFile) if err != nil { // Invalid YAML, show error return err } // 4. Validate if err := configmanager.ValidateConfig(conf); err != nil { // Validation failed return err } // 5. If already running, restart if app.Active() { app.Stop(false) time.Sleep(3 * time.Second) } // 6. Start with new config app.Start(conf) ``` -------------------------------- ### Install Colima via Binary Source: https://github.com/abiosoft/colima/blob/main/skills/references/install.md Download the latest binary release and move it to a directory in your PATH. ```sh # download binary curl -LO https://github.com/abiosoft/colima/releases/latest/download/colima-$(uname)-$(uname -m) # install in $PATH sudo install colima-$(uname)-$(uname -m) /usr/local/bin/colima ``` -------------------------------- ### Running AI Models Source: https://github.com/abiosoft/colima/blob/main/skills/references/runtimes.md Setup and execution of AI models using krunkit. ```sh colima start --runtime docker --vm-type krunkit colima model setup colima model run gemma3 ``` ```sh colima model run gemma3 # Docker AI Registry (default, no prefix) colima model run hf://tinyllama # HuggingFace colima model run ollama://tinyllama --runner ramalama # Ollama (ramalama runner) ``` -------------------------------- ### Execute Sequential Command Chain Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/cli.md Example of initializing a command chain and executing multiple operations sequentially. ```go package main import ( "context" "github.com/abiosoft/colima/cli" ) func main() { chain := cli.New("docker") ctx := context.Background() actions := chain.Init(ctx) logger := chain.Logger(ctx) logger.Info("Starting Docker runtime operations") // Add operations to the chain actions.Add(func() error { return cli.Command("docker", "version").Run() }) if err := actions.Exec(); err != nil { logger.Fatal(err) } } ``` -------------------------------- ### Install Colima via MacPorts Source: https://github.com/abiosoft/colima/blob/main/skills/references/install.md Install Colima using the MacPorts package manager. ```sh sudo port install colima ``` -------------------------------- ### Start Colima with Custom CPU, Memory, and Disk Source: https://github.com/abiosoft/colima/blob/main/README.md Create a Colima VM with specified CPU, memory, and disk size. Adjust these values based on your workload requirements. ```bash colima start --cpu 1 --memory 2 --disk 10 ``` -------------------------------- ### Install Colima on Arch Linux Source: https://github.com/abiosoft/colima/blob/main/skills/references/install.md Install required dependencies and Colima via the AUR. ```sh sudo pacman -S qemu-full go docker # dependencies yay -S lima-bin colima-bin # Lima + Colima from AUR ``` -------------------------------- ### Starting Colima with Different Runtimes Source: https://github.com/abiosoft/colima/blob/main/skills/SKILL.md Commands to initialize Colima with various supported runtimes and features. ```bash colima start ``` ```bash colima start --runtime containerd ``` ```bash colima start --kubernetes ``` ```bash colima start --runtime incus ``` ```bash colima start --runtime docker --vm-type krunkit ``` ```bash colima model run gemma3 ``` -------------------------------- ### Usage Pattern: Conditional Binfmt Setup Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/core.md Pattern for optionally enabling binfmt based on configuration. ```go conf := configmanager.LoadInstance() if conf.Binfmt != nil && *conf.Binfmt { if err := core.SetupBinfmt(host, guest, conf.Arch); err != nil { log.Warnf("Failed to setup binfmt: %v\n", err) // Non-fatal; continue } } ``` -------------------------------- ### Configuring Registry Mirrors Source: https://github.com/abiosoft/colima/blob/main/skills/SKILL.md Command to start Colima with a registry mirror URL. ```bash colima start --registry-mirror ``` -------------------------------- ### Starting and Using Incus Source: https://github.com/abiosoft/colima/blob/main/skills/references/runtimes.md Usage for the Incus runtime and network configuration. ```sh colima start --runtime incus # needs incus (brew install incus) incus launch images:alpine/edge incus list ``` ```sh colima stop colima start --network-address ``` -------------------------------- ### Start Colima for AI Models with GPU Acceleration Source: https://github.com/abiosoft/colima/blob/main/README.md Starts Colima with the Docker runtime and `krunkit` VM type for GPU-accelerated AI workloads. Requires macOS 13+ and Apple Silicon. ```bash colima start --runtime docker --vm-type krunkit colima model run gemma3 ``` -------------------------------- ### Initialize a new App instance Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/app.md The New() constructor verifies that Lima is installed and accessible before returning an App instance. ```go func New() (App, error) ``` -------------------------------- ### Building from Source - Clone and Build Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Clones the Colima repository, navigates into it, and builds the project. ```bash # clone repo and cd into it git clone https://github.com/abiosoft/colima cd colima make sudo make install ``` -------------------------------- ### Install Colima with MacPorts Source: https://github.com/abiosoft/colima/blob/main/README.md Use this command to install Colima via MacPorts. Requires sudo privileges. ```shell sudo port install colima ``` -------------------------------- ### Verify system dependencies Source: https://github.com/abiosoft/colima/blob/main/_autodocs/errors.md Commands to verify the installation and version of required dependencies. ```bash # Check Lima limactl info # Check Docker docker version # Check Krunkit krunkit --version ``` -------------------------------- ### New() Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/app.md Creates a new App instance and verifies that Lima is installed and accessible. ```APIDOC ## func New() ### Description Creates a new App instance. Verifies that Lima (the underlying VM manager) is installed and accessible. ### Returns - **App** - A new application instance - **error** - Error if dependency check fails (e.g., Lima not installed) ``` -------------------------------- ### Provision Runner Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Ensure the runner is ready for use. This is a no-op for Docker but performs installation for Ramalama. ```go func (r *ramalamaRunner) EnsureProvisioned() error ``` ```go runner, _ := model.GetRunner(model.RunnerRamalama) if err := runner.EnsureProvisioned(); err != nil { log.Fatalf("Failed to provision runner: %v\n", err) } log.Println("Runner provisioned") ``` -------------------------------- ### Example store.json file Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/store.md The persistent JSON representation of the store state. ```json { "disk_formatted": true, "disk_runtime": "docker", "ramalama_provisioned": false } ``` -------------------------------- ### Configure Verbose Logging Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/cli.md Example of enabling verbose mode to increase command output detail. ```go import ( "github.com/abiosoft/colima/cli" ) // Enable verbose mode cli.Settings.Verbose = true // Now commands will log more details cmd := cli.Command("docker", "info") cmd.Run() ``` -------------------------------- ### Colima Help Commands Source: https://github.com/abiosoft/colima/blob/main/README.md Access help information for Colima and its start command to understand available options and configurations. ```bash colima --help ``` ```bash colima start --help ``` -------------------------------- ### Serve a model with Go Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Starts a blocking model server on a specified port. Ensure the model is available before calling this method. ```go runner, _ := model.GetRunner(model.RunnerDocker) // Ensure model is available _, _ = runner.EnsureModel("gemma3") // Start serving on port 8000 (blocking) if err := runner.Serve("gemma3", 8000); err != nil { log.Fatalf("Failed to serve model: %v\n", err) } ``` -------------------------------- ### Manage Colima Profiles Source: https://github.com/abiosoft/colima/blob/main/_autodocs/configuration.md Commands to start Colima with default or specific named profiles. ```bash # Use default profile colima start # Use named profile colima start --profile staging colima start -p production # Configuration files: # ~/.colima/default/colima.yaml # ~/.colima/staging/colima.yaml # ~/.colima/production/colima.yaml ``` -------------------------------- ### Edit Configuration Before Startup Source: https://github.com/abiosoft/colima/blob/main/_autodocs/configuration.md Opens the configuration file for editing immediately before starting the Colima instance. ```bash colima start --edit ``` -------------------------------- ### Implement Retry Pattern Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/cli.md Example of using the Action interface to retry a Docker command. ```go chain := cli.New("docker") actions := chain.Init(ctx) // Retry an operation up to 5 times with 1 second between attempts actions.Retry("Wait for Docker", time.Second, 5, func(attempt int) error { return cli.Command("docker", "info").Run() }) if err := actions.Exec(); err != nil { log.Fatal(err) } ``` -------------------------------- ### Run AI Models with Colima Source: https://github.com/abiosoft/colima/blob/main/README.md Examples of running AI models using Colima. Supports different registries and runners like Docker, HuggingFace, and Ollama. ```bash colima model run gemma3 colima model run llama3.2 colima model run hf.co/microsoft/Phi-3-mini-4k-instruct-gguf colima model run ollama://gemma3 --runner ramalama ``` -------------------------------- ### Complete Colima Configuration YAML Source: https://github.com/abiosoft/colima/blob/main/_autodocs/configuration.md A comprehensive example of a colima.yaml file covering all available configuration options including VM resources, networking, mounts, and runtime settings. ```yaml # VM Specifications cpu: 4 # Number of CPU cores (default: 2) memory: 8 # Memory in GiB (default: 2) disk: 100 # Disk size in GiB (default: 100) rootDisk: 0 # Root filesystem disk size in GiB (default: same as disk) arch: aarch64 # Target architecture: "x86_64" or "aarch64" (default: host arch) cpuType: host # CPU model type (e.g., "host" to expose host CPU) # Hostname hostname: colima # VM hostname (default: "colima") # Network Configuration network: address: true # Assign network address to VM dns: # Custom DNS resolvers - 8.8.8.8 - 1.1.1.1 dnsHosts: # Local hostname resolution app.local: 192.168.1.10 hostAddresses: true # Make host addresses accessible from VM mode: shared # Network mode: "shared" (NAT) or "bridged" (default: shared) interface: en0 # Bridge interface when mode is "bridged" preferredRoute: false # Use VM as preferred route gatewayAddress: 192.168.1.1 # Custom gateway IP # Environment Variables env: # Environment variables to set in VM http_proxy: http://proxy.example.com:8080 https_proxy: https://proxy.example.com:8080 # SSH Configuration sshPort: 22 # SSH port inside VM (default: 22) forwardAgent: true # Forward SSH agent from host (default: false) sshConfig: true # Generate/manage SSH config on host (default: false) # VM Type and Features vmType: vz # VM backend: "qemu", "vz" (macOS 13+), "krunkit" (M-series) rosetta: true # Enable Rosetta 2 emulation on vz (Apple Silicon only) binfmt: true # Enable binfmt for cross-architecture containers nestedVirtualization: false # Enable nested virtualization diskImage: /path/to/image # Custom disk image (local file path only) diskImageMirror: https://mirror.example.com/colima # Custom mirror URL forceDiskImage: false # Force re-download of disk image portForwarder: grpc # Port forwarder: "ssh", "grpc", "none" (default: grpc) # Volume Mounts mounts: # Volume mounts from host to VM - location: /path/to/project mountPoint: /workspace # Optional; defaults to same as location writable: true - location: /var/log writable: false mountType: sshfs # Mount protocol: "9p", "sshfs", "virtiofs" (macOS 13+) mountInotify: true # Enable iNotify event reporting # Container Runtime runtime: docker # Runtime: "docker", "containerd", "incus", "none" autoActivate: true # Auto-activate runtime client on host (default: true) # AI Models modelRunner: docker # Model runner: "docker" (default) or "ramalama" # Kubernetes kubernetes: enabled: true version: v1.28.0 # K3s version k3sArgs: # Additional K3s arguments - --disable=traefik,local-storage,metrics-server port: 6443 # Kubernetes API port # Docker Configuration docker: insecure-registries: - registry.example.com registry-mirrors: - https://mirror.docker.com # Provision Scripts provision: - mode: after-boot script: | sudo apt-get update sudo apt-get install -y git - mode: ready script: docker pull ubuntu:latest ``` -------------------------------- ### SetupBinfmt() Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/core.md Configures binfmt support in the VM to enable cross-architecture container execution. ```APIDOC ## func SetupBinfmt(host, guest, arch) ### Description Sets up `binfmt` support in the VM. It determines the required QEMU architecture based on the target guest architecture and installs the necessary binary formats. ### Parameters - **host** (hostActions) - Required - Host interface for diagnostics. - **guest** (guestActions) - Required - Guest (VM) interface to run commands in. - **arch** (environment.Arch) - Required - Target guest architecture (environment.X8664 or environment.AARCH64). ### Returns - **error** - Nil on success; error if setup fails. ``` -------------------------------- ### Common Error Handling Scenarios Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/core.md Examples of handling specific error cases for Lima and binfmt operations. ```go // Lima not installed if err := core.LimaVersionSupported(); err != nil { // err = "error checking Lima version: exec.ExitError" } // Lima version too old if err := core.LimaVersionSupported(); err != nil { // err = "minimum Lima version supported is v0.18.0, current version is v0.17.0" } // binfmt not found in VM if err := core.SetupBinfmt(host, guest, environment.AARCH64); err != nil { // err = "binfmt not found: exit code 127" } ``` -------------------------------- ### Manage instance lifecycle Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/app.md Demonstrates configuring a specific instance with custom resources and Kubernetes, then stopping it. ```go package main import ( "log" "github.com/abiosoft/colima/app" "github.com/abiosoft/colima/config" ) func main() { a, err := app.New() if err != nil { log.Fatal(err) } // Configure a Docker instance with Kubernetes conf := config.Config{ CPU: 4, Memory: 8, Disk: 100, Runtime: "docker", Kubernetes: config.Kubernetes{ Enabled: true, }, } // Start the instance if err := a.Start(conf); err != nil { log.Fatal(err) } // Get the runtime name rt, err := a.Runtime() if err != nil { log.Fatal(err) } log.Printf("Running with runtime: %s\n", rt) // Later, stop the instance if err := a.Stop(false); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Switching Colima Runtimes Source: https://github.com/abiosoft/colima/blob/main/skills/SKILL.md Commands to delete existing data and start Colima with a specific container runtime. ```bash colima delete --data && colima start --runtime ``` -------------------------------- ### Install Colima AI skill for Claude Source: https://github.com/abiosoft/colima/blob/main/docs/FAQ.md Copies the Colima skills directory to the Claude configuration path for AI assistant integration. ```sh cp -R skills ~/.claude/skills/colima ``` -------------------------------- ### Start Colima with Rosetta 2 Emulation Source: https://github.com/abiosoft/colima/blob/main/README.md Enables Rosetta 2 emulation within the Colima VM using the `vz` VM type. Requires macOS 13+ on Apple Silicon. ```bash colima start --vm-type=vz --vz-rosetta ``` -------------------------------- ### Import Configuration from Template Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/configmanager.md Shows how to initialize a configuration from a YAML template file, customize it, and save it to a specific profile path. ```go // Load from template conf, err := configmanager.LoadFrom("./templates/production.yaml") if err != nil { log.Fatal(err) } // Customize conf.Hostname = "prod-colima-1" // Validate if err := configmanager.ValidateConfig(conf); err != nil { log.Fatal(err) } // Save to profile if err := configmanager.SaveToFile(conf, "~/.colima/production/colima.yaml"); err != nil { log.Fatal(err) } ``` -------------------------------- ### Install Colima Skill for Claude Code Source: https://github.com/abiosoft/colima/blob/main/skills/README.md Copy the skill folder to either the user-level or project-level directory to enable it in Claude Code. ```sh # user-level (available in every project) cp -R skills ~/.claude/skills/colima # or project-level cp -R skills /.claude/skills/colima ``` -------------------------------- ### Install Colima Skill for Other Agents Source: https://github.com/abiosoft/colima/blob/main/skills/README.md Copy the skill folder to the target agent's skills directory or configure the skills path directly. ```sh cp -R skills ~/.kimi-code/skills/colima # Kimi Code ``` ```sh kimi --skills-dir ``` -------------------------------- ### Use HostActions for Host Interaction Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/environment.md Demonstrates initializing the host environment and performing basic command execution, file reading, and environment variable retrieval. ```go import ( "github.com/abiosoft/colima/environment/host" ) h := host.New() // Run a command if err := h.Run("brew", "install", "lima"); err != nil { log.Fatal(err) } // Read a file content, err := h.Read("/etc/hosts") if err != nil { log.Fatal(err) } // Get environment variable dockerHome := h.Env("DOCKER_HOME") log.Printf("Docker home: %s\n", dockerHome) ``` -------------------------------- ### Arch Linux - Dependencies Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Installs necessary dependencies for Colima on Arch Linux. ```bash sudo pacman -S qemu-full go docker ``` -------------------------------- ### Nix - Nix Shell Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Installs Colima for use solely within a nix-shell. ```bash nix-shell -p colima ``` -------------------------------- ### Nix - Stable Version Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Installs the stable version of Colima using Nix. ```bash nix-env -i colima ``` -------------------------------- ### MacPorts - Stable Version Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Installs the stable version of Colima using MacPorts. ```bash sudo port install colima ``` -------------------------------- ### Configure Docker with Kubernetes and Mounts Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/config.md Shows how to define a complex configuration including Kubernetes settings and custom host-to-VM mounts. ```go conf := config.Config{ CPU: 4, Memory: 8, Disk: 100, Runtime: "docker", Kubernetes: config.Kubernetes{ Enabled: true, Version: "v1.28.0", K3sArgs: []string{"--disable=traefik,local-storage"}, }, Mounts: []config.Mount{ {Location: "/path/to/project", MountPoint: "/workspace", Writable: true}, {Location: "/var/db", Writable: false}, }, MountType: "sshfs", } ``` -------------------------------- ### Homebrew - Development Version Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Installs the development version of Colima using Homebrew. ```bash brew install --HEAD colima ``` -------------------------------- ### Homebrew - Stable Version Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Installs the stable version of Colima using Homebrew. ```bash brew install colima ``` -------------------------------- ### Configure Kubernetes Source: https://github.com/abiosoft/colima/blob/main/_autodocs/configuration.md Enable Kubernetes and specify version, startup arguments, and API port. ```yaml kubernetes: enabled: true version: v1.28.0 k3sArgs: - --disable=traefik,local-storage,metrics-server port: 6443 ``` -------------------------------- ### Install Colima Latest Development Version (Homebrew) Source: https://github.com/abiosoft/colima/blob/main/README.md Install the bleeding-edge version of Colima using Homebrew. Use with caution. ```shell brew install --HEAD colima ``` -------------------------------- ### Arch Linux - Lima and Colima from Aur Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Installs Lima and Colima from the Arch User Repository (AUR). ```bash yay -S lima-bin colima-bin ``` -------------------------------- ### Track disk provisioning Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/store.md Demonstrates updating the store state after disk provisioning and checking the status before execution. ```go package main import ( "log" "github.com/abiosoft/colima/store" ) func provisionDisk(runtime string) error { // ... provisioning logic ... // After successful provisioning, mark it return store.Set(func(s *store.Store) { s.DiskFormatted = true s.DiskRuntime = runtime }) } func main() { s, _ := store.Load() if s.DiskFormatted && s.DiskRuntime == "docker" { log.Println("Disk already provisioned for docker") return } if err := provisionDisk("docker"); err != nil { log.Fatal(err) } log.Println("Disk provisioned successfully") } ``` -------------------------------- ### Starting VMNet daemon (bridged mode) Source: https://github.com/abiosoft/colima/blob/main/embedded/network/sudo.txt This command starts the VMNet daemon in bridged mode, enabling it to manage network interfaces for Colima. ```bash %staff ALL=(root:wheel) NOPASSWD:NOSETENV: /opt/colima/bin/socket_vmnet --vmnet-mode bridged --socket-group staff * ``` -------------------------------- ### Migrate configuration from file Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/configmanager.md Loads configuration from a source file and saves it to the current profile's location. ```go // Import configuration from a template if err := configmanager.SaveFromFile("./templates/docker-with-k8s.yaml"); err != nil { log.Fatal(err) } ``` -------------------------------- ### Starting VMNet daemon (shared mode) Source: https://github.com/abiosoft/colima/blob/main/embedded/network/sudo.txt This command starts the VMNet daemon in shared mode, allowing it to manage network interfaces for Colima. ```bash %staff ALL=(root:wheel) NOPASSWD:NOSETENV: /opt/colima/bin/socket_vmnet --vmnet-mode shared --socket-group staff --vmnet-gateway 192.168.106.1 --vmnet-dhcp-end 192.168.106.254 * ``` -------------------------------- ### GetCurrentVersion() string Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Returns the currently installed version of the runner. ```APIDOC ## GetCurrentVersion() string ### Description Returns the currently installed version of the runner. ### Returns - **string** - Version string, or empty if not installed ``` -------------------------------- ### Build Colima from Source Source: https://github.com/abiosoft/colima/blob/main/skills/references/install.md Clone the repository and build the binary using make. ```sh git clone https://github.com/abiosoft/colima cd colima make sudo make install ``` -------------------------------- ### Get Display Name Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Retrieve the human-readable name of the runner instance. ```go func (r *dockerRunner) DisplayName() string ``` -------------------------------- ### Load store state in Go Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/store.md Demonstrates loading the store state from the current profile. ```go package main import ( "log" "github.com/abiosoft/colima/store" ) func main() { s, err := store.Load() if err != nil { log.Printf("Error loading store: %v\n", err) return } log.Printf("Disk formatted: %v\n", s.DiskFormatted) log.Printf("Disk runtime: %s\n", s.DiskRuntime) } ``` -------------------------------- ### LimaVersionSupported() Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/core.md Verifies that the installed Lima version meets the minimum requirement of v0.18.0. ```APIDOC ## func LimaVersionSupported() ### Description Verifies that the installed Lima version meets the minimum version requirement by running `limactl info` and comparing the version string. ### Returns - **error** - Nil if Lima version is supported; error if version is too old, Lima is not installed, or parsing fails. ``` -------------------------------- ### Configure VM Backend Source: https://github.com/abiosoft/colima/blob/main/_autodocs/configuration.md Select the virtualization backend and runtime features. ```yaml vmType: vz rosetta: true ``` ```yaml vmType: krunkit runtime: docker ``` -------------------------------- ### Execute standard commands with Command() Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/cli.md Creates an os/exec.Cmd with standard output streaming to stdout/stderr. Use for non-interactive command execution. ```go func Command(command string, args ...string) *exec.Cmd ``` ```go package main import ( "log" "github.com/abiosoft/colima/cli" ) func main() { // Simple command cmd := cli.Command("docker", "version") if err := cmd.Run(); err != nil { log.Fatal(err) } // Command with multiple arguments cmd = cli.Command("docker", "run", "-it", "ubuntu:latest", "bash") if err := cmd.Run(); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Ramalama provisioning workflow Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/store.md Shows how to check and update the store state for Ramalama provisioning. ```go package main import ( "log" "github.com/abiosoft/colima/store" ) func setupRamalama() error { // ... installation logic ... // Mark as provisioned return store.Set(func(s *store.Store) { s.RamalamaProvisioned = true }) } func main() { s, _ := store.Load() if !s.RamalamaProvisioned { if err := setupRamalama(); err != nil { log.Fatal(err) } } log.Println("Ramalama is provisioned") } ``` -------------------------------- ### Define Provisioning Scripts Source: https://github.com/abiosoft/colima/blob/main/skills/references/configuration.md Configures system-level provisioning scripts to run during VM boot. ```yaml # $HOME/.colima/_lima/_config/override.yaml provision: - mode: system script: | #!/bin/bash set -eux -o pipefail apt-get update && apt-get install -y curl ``` ```diff - provision: [] + provision: + - mode: system + script: | + #!/bin/bash + set -eux -o pipefail + apt-get update && apt-get install -y curl ``` -------------------------------- ### Get Environment Profile Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/config.md Retrieves the profile name from the COLIMA_PROFILE environment variable. ```go func EnvProfile() string ``` ```go profile := config.EnvProfile() if profile != "" { log.Printf("Using profile from env: %s\n", profile) } ``` -------------------------------- ### Retrieve runner version with Go Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/model-runner.md Fetches the currently installed version string of the runner. ```go runner, _ := model.GetRunner(model.RunnerRamalama) version := runner.GetCurrentVersion() log.Printf("Current version: %s\n", version) ``` -------------------------------- ### Autostart Colima with Brew Source: https://github.com/abiosoft/colima/blob/main/docs/FAQ.md Use Homebrew services to manage Colima as a background process. ```sh brew services start colima ``` -------------------------------- ### Binary - Download Source: https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md Downloads the Colima binary from the latest release. ```sh # download binary curl -LO https://github.com/abiosoft/colima/releases/latest/download/colima-$(uname)-$(uname -m) ``` -------------------------------- ### Usage Pattern: Pre-Startup Validation Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/core.md Standard pattern for validating Lima before VM provisioning. ```go if err := core.LimaVersionSupported(); err != nil { return fmt.Errorf("lima compatibility error: %w", err) } ``` -------------------------------- ### Define Provisioning script configuration Source: https://github.com/abiosoft/colima/blob/main/_autodocs/types.md Defines a script to be executed during the provisioning process. ```go type Provision struct { Mode string `yaml:"mode"` Script string `yaml:"script"` } ``` -------------------------------- ### Load configuration using Go Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/configmanager.md Loads the configuration for the current profile from its YAML file. ```go package main import ( "log" "github.com/abiosoft/colima/config/configmanager" ) func main() { conf, err := configmanager.Load() if err != nil { log.Fatalf("Failed to load config: %v\n", err) } log.Printf("Runtime: %s\n", conf.Runtime) log.Printf("CPU: %d\n", conf.CPU) } ``` -------------------------------- ### Load configuration from a specific file path Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/configmanager.md Loads configuration from a custom YAML file path. ```go conf, err := configmanager.LoadFrom("/path/to/custom/config.yaml") if err != nil { log.Fatal(err) } ``` -------------------------------- ### Access Version Information Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/config.md Defines the structure for application versioning and demonstrates how to retrieve current version details. ```go type VersionInfo struct { Version string Revision string } ``` ```go vi := config.AppVersion() log.Printf("Colima version: %s (revision: %s)\n", vi.Version, vi.Revision) ``` -------------------------------- ### Get store file path Source: https://github.com/abiosoft/colima/blob/main/_autodocs/api-reference/store.md Retrieves the full path to the store.json file for the current profile. ```go func storeFile() string ``` -------------------------------- ### Perform idempotent Colima startup Source: https://github.com/abiosoft/colima/blob/main/skills/references/automation.md Start a Colima profile only if it is not already running to prevent script failures. ```sh #!/usr/bin/env bash set -euo pipefail PROFILE="${COLIMA_PROFILE:-default}" if ! colima status --profile "$PROFILE" >/dev/null 2>&1; then colima start --profile "$PROFILE" \ --cpu 4 --memory 8 --disk 100 \ --runtime docker else echo "colima '$PROFILE' already running" fi ``` -------------------------------- ### Configure miscellaneous VM settings Source: https://github.com/abiosoft/colima/blob/main/_autodocs/configuration.md Set hostname, environment variables, binfmt support, and port forwarding methods. ```yaml hostname: myvm env: http_proxy: http://proxy.example.com:8080 binfmt: true portForwarder: grpc ``` -------------------------------- ### Identify Runc Error Source: https://github.com/abiosoft/colima/blob/main/docs/FAQ.md Example of a common error message related to cgroup mounting in older versions. ```console runc run failed: unable to start container process: error during container init: error mounting "cgroup" to rootfs at "/sys/fs/cgroup": mount cgroup:/sys/fs/cgroup/openrc (via /proc/self/fd/6), flags: 0xf, data: openrc: invalid argument ``` -------------------------------- ### Customizing VM Resources and Features Source: https://github.com/abiosoft/colima/blob/main/skills/SKILL.md Commands to set CPU, memory, and disk resources, or enable specific VM types like Rosetta 2. ```bash colima start --cpu 4 --memory 8 --disk 100 # at create time colima stop && colima start --cpu 4 --memory 8 # change an existing VM (disk can only grow) colima start --vm-type=vz --vz-rosetta # Rosetta 2 (v0.5.3+, Apple Silicon, macOS 13+) ``` -------------------------------- ### Generate Default Configuration Template Source: https://github.com/abiosoft/colima/blob/main/docs/FAQ.md Create a template file to serve as the base for new configurations. ```sh colima template ``` -------------------------------- ### Configure DNS and Verify Connectivity Source: https://github.com/abiosoft/colima/blob/main/skills/references/troubleshooting.md Set custom DNS servers and verify network access from within the VM. ```sh colima start --dns 8.8.8.8 --dns 1.1.1.1 colima ssh -- ping -c4 google.com ```