Getting Started
Based on container2wasm v0.8.x. Commands assume a Linux or macOS host with Docker Buildx and a WASI runtime available.
Prerequisites
- Docker with Buildx (the conversion runs through BuildKit).
- A WASI runtime to execute the output, for example wasmtime.
- To build
c2wfrom source, a Go toolchain andmake. Prebuilt binaries are also published on the releases page.
Install
make
sudo make installmake builds the c2w and c2w-net binaries (Makefile:16, Makefile:19); sudo make install places them on your PATH. Alternatively, download a release binary from the project's releases page.
A first working setup
Convert a container image to a
.wasmfile. This drives Docker Buildx and can take a while on the first run.bashc2w ubuntu:22.04 out.wasmRun the output on a WASI runtime. The
.wasmboots an emulated Linux and runs the command in the container.bashwasmtime out.wasm uname -aMap a host directory into the guest. The WASI filesystem exposes it and the emulator mounts it over 9p.
bashwasmtime --mapdir /mnt/share::/tmp/share out.wasm cat /mnt/share/from-host
To target riscv64 instead of the default amd64, pass --target-arch:
c2w --target-arch=riscv64 riscv64/ubuntu:22.04 out.wasmFor a browser build, use --to-js to emit JavaScript and Wasm assets:
c2w --to-js alpine:3.20 /tmp/out-js/htdocs/Verify it works
If wasmtime out.wasm uname -a prints a Linux kernel string, the emulator booted, runc started the container, and the command ran inside it. Because the default optimization mode uses a wizer pre-boot snapshot (Dockerfile:29), startup skips the kernel boot and resumes from the snapshot, so the first line of output should appear quickly. Networking needs the host-side c2w-net helper, since WASI has no sockets.
Where to go next
- The README documents supported runtimes, browser output, and networking with
c2w-net. - Note the license caveat before redistributing: the generated
.wasmbundles emulator code under LGPL-2.1 and other licenses. - The project is experimental and CNCF Sandbox stage; treat performance and stability accordingly.
Sources
- container2wasm README, accessed 2026-06-26.
- container2wasm source at commit
74662a2, accessed 2026-06-26.