Introduction
WebAssembly, usually shortened to Wasm, is often described as the third wave of cloud computing, following virtual machines and containers. Wasm apps are smaller, faster, and more portable than traditional Linux containers, and Docker has evolved to support building, sharing, and running them using the same familiar tools.
What Wasm Is
Wasm is a virtual machine architecture that programming languages can compile to, instead of targeting a specific OS and CPU architecture like Linux on ARM or AMD. A Wasm binary can run anywhere a Wasm runtime is available. Docker Desktop ships with several such runtimes, including io.containerd.spin.v2, which allows containerd to deploy and manage Wasm containers — Wasm binaries running inside minimal scratch containers.
Wasm currently excels at workloads like AI inference, serverless functions, plugins, and edge computing, but is less suited to apps with heavy I/O or complex networking requirements — though this is expected to improve as the ecosystem matures.
Setting Up the Environment
Working with Wasm requires Docker Desktop with the Wasm feature enabled, Rust with the Wasm compilation target installed, and Spin, a framework for building and running Wasm apps. The Wasm target for Rust is added with:
rustup target add wasm32-wasip1Writing a Wasm App
A new Wasm-based web app can be scaffolded with Spin:
spin new hello-world -t http-rustThis generates a simple Rust web app. After editing the response text and compiling it, Spin produces a .wasm binary:
spin buildThe resulting binary can be tested locally before containerizing it:
spin upContainerizing the App
Packaging a Wasm app as a container image still uses a Dockerfile, but based on the empty scratch image, since Wasm apps don't need a Linux OS:
FROM scratch
COPY /target/wasm32-wasip1/release/hello_world.wasm .
COPY spin.toml .The image is then built with a Wasm-specific platform flag:
docker build --platform wasi/wasm --provenance=false -t nigelpoulton/ddd-book:wasm .The resulting image looks and behaves like a regular Docker image, just dramatically smaller — often only a few hundred kilobytes. It can be pushed to Docker Hub or any other OCI registry using the standard docker push command.
Running a Wasm Container
Running the containerized app requires specifying the Wasm runtime explicitly:
docker run -d --name wasm-ctr \
--runtime=io.containerd.spin.v2 \
--platform=wasi/wasm \
-p 5556:80 \
nigelpoulton/ddd-book:wasm /Once running, the app behaves exactly like any other containerized web service and can be reached through the mapped port.
Conclusion
Docker's support for Wasm means developers can use the exact same tools — docker build, docker push, docker run, and standard OCI registries — to package and distribute Wasm apps as they already do for traditional containers. As the Wasm ecosystem continues to mature, this integration positions Docker to support both models side by side, letting teams choose the right tool for each workload.