C2w
Container to WASM converter
About this project
C2W
Enhanced Fork: This repository is a feature-packed, cross-platform fork of the original container2wasm project by ashu-choudhury, heavily expanded with full native Windows support, automated folder and Dockerfile conversion, smart default output naming, and instant registry build caching.
What is C2W?
C2W is an advanced container-to-WebAssembly image converter. It empowers you to convert any Docker image or local application folder directly into a WebAssembly (Wasm) file and run unmodified Linux containers anywhere Wasm lives—across standard Wasm runtimes and right inside your web browser.
Whether you want to spin up custom microservices or run an entire operating system inside a secure sandbox, C2W bridges the gap between containerization and WebAssembly.
✨ Key Features
- Convert Docker Images & Folders to Wasm: Instantly transform standard OCI images or local project directories containing a
Dockerfileinto a standalone.wasmfile with a single command. - Run Linux in the Browser: Take your favorite operating systems, distributions, and containerized apps straight into the browser or across every supported platform that runs Wasm.
- Full Native Cross-Platform CLI: Built from the ground up for seamless usage across Windows, Linux, and macOS.
- Smart Output Naming: Automatically names generated Wasm files based on your project folder (e.g.,
c2w .->my-app.wasm) or container tag. - Blazing Fast Builds: Leverages integrated remote registry cache pulling to fetch pre-built engine layers instantly, bypassing long local compilation times.
- WASI & Browser-Ready: Execute smoothly on standard WASI runtimes (
wasmtime,wazero,wamr, etc.) or export directly into browser-compatible JavaScript and WebAssembly bundles (--to-js). - Networking & Filesystem Support: Includes built-in user-space networking (
c2w-net) and VirtIO 9P directory mounting for seamless host-to-guest file sharing.
🚀 Quick Start Examples
1. Build Wasm from a Local Application Directory
Inside any folder containing a Dockerfile:
c2w .
(Automatically detects your Dockerfile, builds the container, and outputs my-app.wasm)
2. Build from a Docker Registry Image
c2w ubuntu:22.04
(Pulls the image and outputs ubuntu_22.04.wasm)
3. Build for Web Browser Deployment
c2w . --to-js ./dist/
🏃 Running Your Wasm Binaries
Using wasmtime:
# Run the default container entrypoint
wasmtime app.wasm
# Pass custom commands
wasmtime app.wasm uname -a
# Map a host directory into the container sandbox
wasmtime --mapdir /mnt/data::/host/path app.wasm cat /mnt/data/file.txt
🛠️ Building from Source
Prerequisites
- Go 1.19+
- Docker with BuildKit enabled
Build Commands
- Windows (PowerShell):
.\build.ps1
- Linux / macOS (Makefile):
make
sudo make install
📜 License & Acknowledgements
- C2W is open-source software licensed under the Apache 2.0 License.
- Forked and enhanced from the original container2wasm project by ashu-choudhury.