Convert Dockerfiles to Firecracker VM images.
- Build VM images from any Dockerfile
- Automatic image size optimization
- Direct console access
- Custom kernel support
git clone https://github.com/noxomix/imagecracker.git
cd imagecracker
./imagecracker.sh setupimagecracker <COMMAND> [OPTIONS] [DIRECTORY]build- Creates a Firecracker image from a Dockerfilerun- Runs/tests a Firecracker imagesetup- Installs symlink for global access
-n, --name NAME- Image name (required)-d, --directory DIR- Output directory (default:$HOME/firebuilds)-k, --kernel KERNEL- Path to vmlinux kernel (default: bundled kernel)--keep-kernel-name- Keep original kernel filename (default: rename to 'kernel')--no-compact- Disable rootfs optimization (keep full size)--no-template- Skip creating vmconfig.json template (created by default)--readonly-rootfs- Mount rootfs as read-only in VM configuration--custom-init- Add init=/init to kernel boot arguments-ed, --extra-disk [SIZE]- Create additional empty ext4 disk (default: 4GB, or specify size in GB)-s, --size SIZE- Initial rootfs size in MB (default: 2048)-h, --help- Show help message
-d, --directory DIR- Image directory (default:$HOME/firebuilds)-c, --config FILE- Use custom Firecracker config file (won't be deleted)--kernel-name NAME- Kernel filename in image directory (default: 'kernel')--ram SIZE- RAM size in MB (default: 256, ignored with custom config)--vcpus COUNT- Number of vCPUs (default: 2, ignored with custom config)--boot-args ARGS- Kernel boot arguments (default: "console=ttyS0 reboot=k panic=1 pci=off", ignored with custom config)--executable PATH- Path to firecracker executable (default: firecracker)-h, --help- Show help message
imagecracker build --name myapp .
# Creates kernel, rootfs.ext4, and vmconfig.jsonimagecracker build --name production /path/to/projectimagecracker build --name fullsize --no-compact /path/to/projectimagecracker build --name bigapp --kernel /path/to/vmlinux --size 4096 .imagecracker build --name myapp --kernel /path/to/mykernel-5.10 --keep-kernel-name .
# This will save the kernel as 'mykernel-5.10' instead of 'kernel'imagecracker build --name testapp --directory /tmp/my-images .imagecracker build --name myapp --no-template .
# Creates only kernel and rootfs.ext4, no vmconfig.jsonimagecracker build --name myapp --extra-disk .
# Creates an additional empty 4GB ext4 disk (extra.ext4)imagecracker build --name myapp --extra-disk 16 .
# Creates an additional empty 16GB ext4 diskimagecracker build --name myapp --extra-disk 8 .
# Creates kernel, rootfs.ext4, extra.ext4 (8GB), and vmconfig.json with both disks configuredimagecracker build --name secure-app --readonly-rootfs .
# Creates VM with rootfs mounted as read-onlyimagecracker build --name stateful-app --readonly-rootfs --extra-disk 4 .
# Rootfs is read-only, extra disk for writable dataimagecracker build --name custom-init-app --custom-init .
# Adds init=/init to boot arguments for custom init systemsimagecracker run myappimagecracker run --ram 512 --vcpus 4 myappimagecracker run -d /path/to/images myappimagecracker run --boot-args "console=ttyS0 init=/bin/bash" myappimagecracker run --executable /usr/local/bin/firecracker myappimagecracker run -c /path/to/config.json myappimagecracker run --kernel-name mykernel-5.10 myapp
# Use this if the image was built with --keep-kernel-nameimagecracker run --ram 1024 --vcpus 8 --boot-args "console=ttyS0 debug" --executable /custom/firecracker myappimagecracker setup- Dockerfile in target directory (see Firecracker-Compatible Dockerfile Examples below)
- Docker installed and running
- Root/sudo access for image operations
- Firecracker installed and in PATH (or custom path specified with
--executable) - Root/sudo access for VM operations
- Pre-built Firecracker images (created with the
buildcommand) - Screen installed (for VM console management)
Important: Firecracker requires init systems (systemd/OpenRC) - see Dockerfile Examples
Images are stored in a structured format:
$HOME/firebuilds/
├── myapp/
│ ├── kernel # Kernel for this VM (default name)
│ ├── rootfs.ext4 # Root filesystem
│ ├── extra.ext4 # Additional disk (if built with --extra-disk)
│ └── vmconfig.json # VM configuration (created by default)
├── production/
│ ├── kernel
│ └── rootfs.ext4
├── custom-app/ # Built with --keep-kernel-name
│ ├── mykernel-5.10 # Original kernel name preserved
│ └── rootfs.ext4
└── ...
- Navigate to a directory with a Dockerfile
- Run
imagecracker build --name <name> . - Images are stored in
$HOME/firebuilds/<name>/
- Run
imagecracker run <name>to start and connect to the VM - Use the console:
- Press Ctrl+A then D to exit and terminate the VM
- Press Ctrl+A then X to kill the VM immediately
- Configure with options like
--ram,--vcpus,--boot-args
# Build an image with default kernel naming
imagecracker build --name webserver .
# Run with default settings (256MB RAM, 2 vCPUs)
imagecracker run webserver
# Exit and terminate the VM (Ctrl+A then D)
# Run with more resources
imagecracker run --ram 512 --vcpus 4 webserver
# Build with custom kernel and preserve its name
imagecracker build --name custom-app --kernel mykernel-5.10 --keep-kernel-name .
# Run the image with custom kernel name
imagecracker run --kernel-name mykernel-5.10 custom-appimagecracker.sh- The main scriptvmlinux- Standard Linux kernel for Firecracker VMsREADME.md- This documentation
- Images are automatically optimized by default
- VM configuration (vmconfig.json) is created by default
- Use
--no-compactonly if you need the full size - Use
--no-templateif you don't need vmconfig.json - Use
--keep-kernel-nameto preserve original kernel filenames - Use
--extra-diskto add a secondary storage disk for data persistence - Use
--readonly-rootfsfor secure, immutable root filesystems - Combine
--readonly-rootfswith--extra-diskfor stateful applications with immutable base
- Default: 256MB RAM, 2 vCPUs
- Wildcard matching:
imagecracker run webmatches any image containing "web" - Configuration priority order:
--configflag (highest priority)vmconfig.jsonin image directory (if exists)- Command-line options like
--ram,--vcpus(lowest priority)
- Use
--boot-args "console=ttyS0 init=/bin/bash"for debugging - Use
--kernel-nameif kernel has custom name
ImageCracker supports multiple ways to configure your Firecracker VMs:
-
Custom Config File (
--config)imagecracker run --config /path/to/config.json myapp
- Highest priority - overrides all other options
- Full control over Firecracker configuration
-
Image Config (
vmconfig.json)# Build creates vmconfig.json by default imagecracker build --name myapp . # Run uses vmconfig.json automatically imagecracker run myapp
- Automatically detected in image directory
- Created by default during build
- Persists with the image
-
Command-line Options
imagecracker run --ram 512 --vcpus 4 myapp
- Used when no config file exists
- Creates temporary configuration
- Deleted after VM terminates
When using --config or an image's vmconfig.json, command-line options like --ram, --vcpus, and --boot-args are ignored with a warning.
ImageCracker provides flexible kernel naming to support different use cases:
- Kernels are saved as
kernelin the image directory - The
runcommand expectskernelby default
If you need to preserve original kernel filenames (e.g., for version tracking):
-
During Build: Use
--keep-kernel-nameflagimagecracker build --name myapp --kernel linux-5.10-custom --keep-kernel-name . # Kernel saved as: linux-5.10-custom
-
During Run: Use
--kernel-nameflagimagecracker run --kernel-name linux-5.10-custom myapp
- Default naming: Best for most users, ensures compatibility
- Custom naming: Useful when:
- Testing multiple kernel versions
- Tracking specific kernel builds
- Maintaining kernel version history
For Firecracker VMs, your Dockerfile needs an init system since Firecracker runs full VMs (not containers). Here are working examples:
FROM ubuntu:20.04
# Avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
# Install systemd and essential packages
RUN apt-get update && apt-get install -y \
systemd \
systemd-sysv \
init \
openssh-server \
curl \
net-tools \
iproute2 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Configure systemd
RUN systemctl set-default multi-user.target
# Disable unnecessary services for faster boot
RUN systemctl mask \
systemd-random-seed.service \
cryptsetup.target \
getty@tty1.service
# Set hostname
RUN echo 'firecracker-vm' > /etc/hostname
# Configure SSH (optional)
RUN mkdir -p /var/run/sshd && \
echo 'root:firecracker' | chpasswd
# Use systemd as PID 1
ENTRYPOINT ["/sbin/init"]FROM alpine:latest
RUN apk add --no-cache openrc util-linux openssh bash && \
rc-update add sshd default && \
echo 'root:alpine' | chpasswd
ENTRYPOINT ["/sbin/init"]- Init System Required: Firecracker VMs need systemd, OpenRC, or custom init
- PID 1: Must use
/sbin/initas entrypoint, not your application - Full VM Environment: Include networking tools, SSH server, etc.
- Hostname Configuration: Set hostname for the VM
This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details.
The included Linux kernel (vmlinux) is licensed under GPLv2 - see KERNEL_LICENSE.md for details.