The Docker Desktop Wasm feature allows you to run Wasm applications alongside your Linux containers. This means that you can use Docker to build, run, and share both Wasm and Linux applications.
To use the Docker Desktop Wasm feature, you need to enable the Wasm feature in the Docker Desktop settings. Once the Wasm feature is enabled, you can create and run Wasm containers just like you would any other Docker container.
Docker sees Wasm as a complementary technology to Linux containers. This is where developers can choose which technology they use (or both!) depending on the use case. And as the community explores what’s possible with Wasm, the effort is to make Wasm applications easier to develop, build, and run using the experience and tools you know and love. Docker solves the traditional problem – it works on my machine, works on yours and in production flawlessly. Docker Desktop and CLI can now manage both Linux containers and Wasm containers side by side.
The Wasm feature is still in Beta. We recommend that you do not use this feature in production environments as this feature may change or be removed from future releases.
Who’s this for?
The Docker Desktop Wasm feature is for developers who want to build, share, and run applications using WebAssembly (WASM). Here are some specific types of developers who might be interested in using the Docker Desktop Wasm feature:
- Developers who want to build high-performance web applications.
- Developers who want to build applications that can run at the edge.
- Developers who want to build microservices.
- Developers who want to use the same tools and workflows for WASM applications as they do for other types of applications.
What problems does Docker solve for the Wasm developer community?
- Conquer App Complexity
If you look at the developer tooling today, it is not easy to set up a development environment for Wasm. It ends up with the same “works in a machine” scenario. “Works on my machine” is a common refrain heard whenever the local environment configuration (from dev to test to production) has drifted from the established baseline and the same is true for Wasm too. It might be a case when you are running a specific version of Rust in your system while your CI infrastructure might be running a different version altogether. The same applies to different runtime or testing tools that you might be using in your development environment.
- Learn and Develop Faster
Understanding Wasm involves a steep learning curve. Multiple languages, runtimes, frameworks, architectures, and discontinuous interfaces between tools for each lifecycle stage might create enormous complexity. Docker simplifies and accelerates your Wasm-based workload development workflow. With well-known commands like docker compose up, docker build and docker push/run, developers can easily build Wasm containers and run it alongside Linux containers.It gives web developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for their projects.
- Collaborate and Innovate
By using Docker, developers can now collaborate with their team members and enhance product functionality by easily publishing images to Docker Hub.
Pre-requisites
- Install the latest version of Docker Desktop
- Turn on Wasm workloads(Wasm workloads require the containerd image store feature to be turned on)
- Open the Docker Desktop Settings.
- Go to Features in development and then select the Beta features tab.
- Check the following checkboxes:
- Use containerd for storing and pulling images
- Enable Wasm
- Select Apply & restart to save the settings.
- In the confirmation dialog, select Install to install the Wasm runtimes.
Docker Desktop downloads and installs the following runtimes that you can use to run Wasm workloads:
- io.containerd.slight.v1
- io.containerd.spin.v1
- io.containerd.wasmedge.v1
- io.containerd.wasmtime.v1
List of Supported Wasm Runtimes
Docker Desktop support the following Wasm runtime:
- Slight: Slight is a lightweight Wasm runtime that is designed to be fast and efficient. It is a good choice for running Wasm workloads that require high performance.
- Spin: Spin is a serverless Wasm runtime that is designed to be easy to use and deploy. It is a good choice for running Wasm workloads that are event-driven or that need to be scaled horizontally.
- WasmEdge: WasmEdge is a full-featured Wasm runtime that supports a wide range of features. It is a good choice for running Wasm workloads that require a high degree of flexibility and control.
- Wasmtime: Wasmtime is a Wasm runtime that is designed to be compatible with the WebAssembly specification. It is a good choice for running Wasm workloads that need to be portable to different environments.
In case you’re interested to see the list of wasm runtimes via CLI, you can run the below command:
Copied!docker run -it --rm --privileged --pid=host justincormack/nsenter1 /bin/ls /var/lib/wasm/runtimes
Result:
Copied!containerd-shim-slight-v1 containerd-shim-wasmtime-v1 containerd-shim-spin-v1 libwasmedge.so.0 containerd-shim-wasmedge-v1 libwasmedge.so.0.0.2
Building and Running Your First Wasm Container
WebAssembly (WASM) can be executed outside of the browser environment using Wasm runtimes that are designed to function on traditional operating systems like Linux, Windows, and macOS.
When running Wasm applications outside of the browser, the Wasm runtime needs to communicate with the host system using interfaces other than the JavaScript engine. One such interface is the WebAssembly System Interface (WASI). WASI provides a standardized way for Wasm modules to interact with the host system, similar to how applications interact with the operating system through POSIX interfaces.
WASI is a relatively new specification, but it is gaining traction in the Wasm community. It is supported by a number of Wasm runtimes, including Wasmtime, Emscripten, and WAGI.
Below is an example how Wasm containers can be built and run on Docker Desktop using WASI:
Installing WASI
WASI is a modular system interface for WebAssembly.
First, download wasi from the following URL:
Copied!wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/wasi-sdk-16.0-macos.tar.gz
Untar the WASI SDK
Copied!tar xvf wasi-sdk-16.0-macos.tar.gz
Create the below file and save it as hello-world.c
Copied!/* C program to print Hello Wasm! */ #include <stdio.h> int main() { printf("Hello, Wasm!"); return 0; }
Create a WASM module using WASI SDK
Copied!export WASI_SDK_PATH=`pwd`/wasi-sdk-16.0 CC="${WASI_SDK_PATH}/bin/clang" $CC hello-world.c -o hello-world.wasm
Verifying the file type
Copied!file hello-world.wasm hello-world.wasm: WebAssembly (wasm) binary module version 0x1 (MVP)
Creating a Dockerfile
Here’s a Dockerfile that you can use to containerize your “Hello, Wasm” C program:
Copied!FROM scratch COPY --chmod=755 hello-world.wasm /hello-world.wasm ENTRYPOINT [ "/hello-world.wasm"
Building the Image
Copied!docker build --platform=wasi/wasm --provenance=false -t hello-world-wasm --load .
Running the container
Copied!docker run --platform=wasi/wasm --rm -i --runtime=io.containerd.wasmedge.v1 hello-world-wasm
Latest posts
-
PostgreSQL, Model Context Protocol (MCP) and Claude Desktop
Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized…
-
Using a Neo4j Graph Database to Power the Internet of Things
Graph databases excel at representing complex relationships between data points, which can be useful in sensor data analysis.For example, if…
-
Expediting Productivity: My Favorite macOS Apps of 2024
As 2024 wraps up, I’ve been reflecting on the tools that helped me get things done this year. If you’re…
Leave a Reply