11# Cocoon
22
3- Lightweight VM manager built on Cloud Hypervisor.
3+ Lightweight MicroVM engine built on [ Cloud Hypervisor] ( https://github.com/cloud-hypervisor/cloud-hypervisor ) .
44
55## Features
66
7- - ** UEFI boot** -- CLOUDHV.fd UEFI firmware by default; direct kernel boot for OCI VM images is also supported (auto-detected from image metadata)
87- ** OCI VM images** -- pull OCI images with kernel + rootfs layers, content-addressed blob cache with SHA-256 deduplication
9- - ** Cloud image support** -- pull from HTTP/HTTPS URLs, automatic qcow2 conversion
8+ - ** Cloud image support** -- pull from HTTP/HTTPS URLs (e.g. Ubuntu cloud images), automatic qcow2 conversion
9+ - ** UEFI boot** -- CLOUDHV.fd firmware by default; direct kernel boot for OCI images (auto-detected)
1010- ** COW overlays** -- copy-on-write disks backed by shared base images (raw for OCI, qcow2 for cloud images)
11- - ** Interactive console** -- ` cocoon vm console ` for bidirectional PTY access to running VMs, SSH-style escape sequences
12- - ** Docker-like CLI** -- ` cocoon vm create ` , ` cocoon vm start ` , ` cocoon vm stop ` , ` cocoon vm list ` , ` cocoon vm rm `
11+ - ** CNI networking** -- automatic NIC creation via CNI plugins, multi-NIC support, per-VM IP allocation
12+ - ** DNS configuration** -- custom DNS servers injected into VMs via kernel cmdline
13+ - ** Cloud-init metadata** -- automatic NoCloud cidata disk for cloudimg VMs (hostname, root password)
14+ - ** Interactive console** -- ` cocoon vm console ` for bidirectional PTY access, SSH-style escape sequences
15+ - ** Docker-like CLI** -- ` create ` , ` run ` , ` start ` , ` stop ` , ` list ` , ` inspect ` , ` console ` , ` rm `
1316- ** Zero-daemon architecture** -- one Cloud Hypervisor process per VM, no long-running daemon
14- - ** Garbage collection** -- automatic tracking and lock-safe GC of unreferenced images, orphaned overlays, and expired temp entries
17+ - ** Garbage collection** -- automatic lock-safe GC of unreferenced images, orphaned overlays, and expired temp entries
18+ - ** Doctor script** -- pre-flight environment check and one-command dependency installation
1519
1620## Requirements
1721
18- - Linux with KVM (x86_64)
22+ - Linux with KVM (x86_64 or aarch64 )
1923- Root access (sudo)
2024- [ Cloud Hypervisor] ( https://github.com/cloud-hypervisor/cloud-hypervisor ) v38.0+
21- - ` qemu-img ` (from qemu-utils package , for cloud images)
25+ - ` qemu-img ` (from qemu-utils, for cloud images)
2226- UEFI firmware (` CLOUDHV.fd ` , for cloud images)
27+ - CNI plugins (` bridge ` , ` host-local ` , ` loopback ` )
2328- Go 1.25+ (build only)
2429
2530## Installation
2631
27- ### go install
32+ ### GitHub Releases
33+
34+ Download pre-built binaries from [ GitHub Releases] ( https://github.com/projecteru2/cocoon/releases ) :
2835
2936``` bash
37+ # Linux amd64
38+ curl -fsSL -o cocoon https://github.com/projecteru2/cocoon/releases/latest/download/cocoon_Linux_x86_64.tar.gz
39+ tar -xzf cocoon_Linux_x86_64.tar.gz
40+ install -m 0755 cocoon /usr/local/bin/
41+
42+ # Or use go install
3043go install github.com/projecteru2/cocoon@latest
3144```
3245
@@ -38,27 +51,43 @@ cd cocoon
3851make build
3952```
4053
41- This produces a ` cocoon ` binary in the project root. Use ` make install ` to install it into ` $GOPATH/bin ` .
54+ This produces a ` cocoon ` binary in the project root. Use ` make install ` to install into ` $GOPATH/bin ` .
55+
56+ ## Doctor
57+
58+ Cocoon ships a diagnostic script that checks your environment and can auto-install all dependencies:
59+
60+ ``` bash
61+ # Check only — reports PASS/FAIL for each requirement
62+ ./doctor/check.sh
63+
64+ # Check and fix — creates directories, sets sysctl, adds iptables rules
65+ ./doctor/check.sh --fix
66+
67+ # Full setup — install cloud-hypervisor, firmware, and CNI plugins
68+ ./doctor/check.sh --upgrade
69+ ```
70+
71+ The ` --upgrade ` flag downloads and installs:
72+ - Cloud Hypervisor + ch-remote (static binaries)
73+ - CLOUDHV.fd firmware (rust-hypervisor-firmware)
74+ - CNI plugins (bridge, host-local, loopback, etc.)
4275
4376## Quick Start
4477
4578``` bash
79+ # Set up the environment (first time)
80+ sudo ./doctor/check.sh --upgrade
81+
4682# Pull an OCI VM image
4783cocoon image pull ubuntu:24.04
4884
4985# Or pull a cloud image from URL
5086cocoon image pull https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img
5187
52- # List cached images
53- cocoon image list
54-
55- # Create and start a VM in one step
88+ # Create and start a VM
5689cocoon vm run --name my-vm --cpu 2 --memory 1G ubuntu:24.04
5790
58- # Or create then start separately
59- cocoon vm create --name my-vm ubuntu:24.04
60- cocoon vm start my-vm
61-
6291# Attach interactive console
6392cocoon vm console my-vm
6493
@@ -81,17 +110,17 @@ cocoon
81110│ └── inspect IMAGE Show detailed image info (JSON)
82111├── vm
83112│ ├── create [flags] IMAGE Create a VM from an image
84- │ ├── run [flags] IMAGE Create and start a VM from an image
113+ │ ├── run [flags] IMAGE Create and start a VM
85114│ ├── start VM [VM...] Start created/stopped VM(s)
86115│ ├── stop VM [VM...] Stop running VM(s)
87116│ ├── list (alias: ls) List VMs with status
88117│ ├── inspect VM Show detailed VM info (JSON)
89- │ ├── console VM Attach interactive console to a running VM
90- │ ├── rm [flags] VM [VM...] Delete VM(s) (--force to stop running VMs first)
91- │ └── debug [flags] IMAGE Generate cloud-hypervisor launch command (dry run)
92- ├── gc Remove unreferenced blobs, boot files, and VM dirs
93- ├── version Show version, git revision, and build timestamp
94- └── completion [bash|zsh|fish|powershell] Generate shell completion script
118+ │ ├── console VM Attach interactive console
119+ │ ├── rm [flags] VM [VM...] Delete VM(s) (--force to stop first)
120+ │ └── debug [flags] IMAGE Generate CH launch command (dry run)
121+ ├── gc Remove unreferenced blobs and VM dirs
122+ ├── version Show version, revision, and build time
123+ └── completion [bash|zsh|fish|powershell]
95124```
96125
97126## Global Flags
@@ -102,6 +131,10 @@ cocoon
102131| ` --root-dir ` | ` COCOON_ROOT_DIR ` | ` /var/lib/cocoon ` | Root directory for persistent data |
103132| ` --run-dir ` | ` COCOON_RUN_DIR ` | ` /var/run/cocoon ` | Runtime directory for sockets and PIDs |
104133| ` --log-dir ` | ` COCOON_LOG_DIR ` | ` /var/log/cocoon ` | Log directory for VM serial logs |
134+ | ` --cni-conf-dir ` | ` COCOON_CNI_CONF_DIR ` | ` /etc/cni/net.d ` | CNI plugin config directory |
135+ | ` --cni-bin-dir ` | ` COCOON_CNI_BIN_DIR ` | ` /opt/cni/bin ` | CNI plugin binary directory |
136+ | ` --root-password ` | ` COCOON_DEFAULT_ROOT_PASSWORD ` | | Default root password for cloudimg VMs |
137+ | ` --dns ` | ` COCOON_DNS ` | ` 8.8.8.8,1.1.1.1 ` | DNS servers for VMs (comma separated) |
105138
106139## VM Flags
107140
@@ -113,6 +146,45 @@ Applies to `cocoon vm create`, `cocoon vm run`, and `cocoon vm debug`:
113146| ` --cpu ` | ` 2 ` | Boot CPUs |
114147| ` --memory ` | ` 1G ` | Memory size (e.g., 512M, 2G) |
115148| ` --storage ` | ` 10G ` | COW disk size (e.g., 10G, 20G) |
149+ | ` --nics ` | ` 1 ` | Number of network interfaces (0 = no network) |
150+
151+ ## Networking
152+
153+ Cocoon uses [ CNI] ( https://www.cni.dev/ ) for VM networking. Each NIC is backed by a TAP device wired through the CNI plugin chain.
154+
155+ - ** Default** : 1 NIC with automatic IP assignment via CNI
156+ - ** No network** : ` --nics 0 ` creates a VM with no network interfaces
157+ - ** Multi-NIC** : ` --nics N ` creates N interfaces; for cloudimg VMs all NICs are auto-configured, for OCI images only the last NIC is auto-configured (others need manual setup inside the guest)
158+ - ** DNS** : Use ` --dns ` to set custom DNS servers (comma separated), injected via kernel cmdline
159+
160+ CNI configuration is read from ` --cni-conf-dir ` (default ` /etc/cni/net.d ` ). A typical bridge config:
161+
162+ ``` json
163+ {
164+ "cniVersion" : " 1.0.0" ,
165+ "name" : " cocoon" ,
166+ "type" : " bridge" ,
167+ "bridge" : " cni0" ,
168+ "isGateway" : true ,
169+ "ipMasq" : true ,
170+ "ipam" : {
171+ "type" : " host-local" ,
172+ "subnet" : " 10.22.0.0/16" ,
173+ "routes" : [{ "dst" : " 0.0.0.0/0" }]
174+ }
175+ }
176+ ```
177+
178+ ## OS Images
179+
180+ Pre-built OCI VM images (Ubuntu 22.04, 24.04) are published to GHCR and auto-built by GitHub Actions when ` os-image/ ` changes:
181+
182+ ``` bash
183+ cocoon image pull ghcr.io/projecteru2/cocoon/ubuntu:24.04
184+ cocoon image pull ghcr.io/projecteru2/cocoon/ubuntu:22.04
185+ ```
186+
187+ These images include kernel, initramfs, and a systemd-based rootfs with an overlayfs boot script.
116188
117189## Shell Completion
118190
@@ -132,7 +204,7 @@ cocoon completion fish > ~/.config/fish/completions/cocoon.fish
132204``` bash
133205make build # Build cocoon binary (CGO_ENABLED=0)
134206make test # Run tests with race detector and coverage
135- make lint # Run golangci-lint (auto-downloads v2.9.0)
207+ make lint # Run golangci-lint
136208make vet # Run go vet for linux and darwin
137209make fmt # Format code with gofumpt + goimports
138210make ci # Full CI pipeline: fmt-check + vet + lint + test + build
0 commit comments