# Introducing the Docker+Wasm Technical Preview

What is Wasm?

[WebAssembly](https://webassembly.org/), often shortened to Wasm, is a relatively new technology that allows you to compile application code written in over 40+ languages (including Rust, C, C++, JavaScript, and Golang) and run it inside sandboxed environments.

The original use cases were focused on running native code in web browsers, such as [Figma](https://www.figma.com/blog/webassembly-cut-figmas-load-time-by-3x/), [AutoCAD](https://blogs.autodesk.com/autocad/autocad-web-app-google-io-2018/), and [Photoshop](https://web.dev/ps-on-the-web/). In fact, [fastq.bio](http://fastq.bio) saw a [20x speed improvement](https://www.smashingmagazine.com/2019/04/webassembly-speed-web-app/) when converting their web-based DNA sequence quality analyzer to Wasm. And Disney built their [Disney+ Application Development Kit](https://medium.com/disney-streaming/introducing-the-disney-application-development-kit-adk-ad85ca139073) on top of Wasm! The benefits in the browser are easy to see.

But Wasm is quickly spreading beyond the browser thanks to the [WebAssembly System Interface](https://wasi.dev/) (WASI). Companies like [Vercel](https://vercel.com/docs/concepts/functions/edge-functions/wasm), [Fastly](https://docs.fastly.com/products/compute-at-edge), [Shopify](https://shopify.engineering/shopify-webassembly), and [Cloudflare](https://developers.cloudflare.com/workers/platform/languages/) support using Wasm for running code at the edge, and [Fermyon](https://www.fermyon.com/) is building a platform to run Wasm microservices in the cloud.

# **Why Docker?**

At Docker, our goal is to help developers bring their ideas to life by conquering the complexity of app development. We strive to make it easy to build, share, and run your application, regardless of the underlying technologies. By making containers accessible to all, we proved our ability to make the lives of developers easier and were recognized as the [#1 most-loved developer tool](https://survey.stackoverflow.co/2022/#section-most-loved-dreaded-and-wanted-other-tools).

We see Wasm as a [complementary technology](https://www.docker.com/blog/why-containers-and-webassembly-work-well-together/) to Linux containers 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, we want to help make Wasm applications easier to develop, build, and run using the experience and tools you know and love.

# **How do I get the technical preview?**

Ready to dive in and try it for yourself? Great! But before you do, a couple quick notes to keep in mind as you start exploring:

* Important note #1: This is a technical preview build of Docker Desktop, and things might not work as expected. Be sure to back up your containers and images before proceeding.
    
* Important note #2: This preview has the [containerd image store](https://docs.docker.com/desktop/containerd/) enabled and cannot be disabled. If you’re not currently using the containerd image store, then pre-existing images and containers will be inaccessible.
    

WASM is no longer in beta. Download [Docker Desktop](https://www.docker.com/products/docker-desktop/) to start using it.

# **Are there any known limitations?**

Yes! This is an early technical preview and we’re still working on making the experience as smooth as possible. But here are a few things you should be aware of:

1. Docker Compose may not exit cleanly when interrupted
    
2. Pushes to Hub might give an error stating `server message: insufficient_scope: authorization failed`, even after logging in using Docker Desktop
    

# **Okay, so how does the Wasm integration actually work?**

We’re glad you asked! First off, we need to remind you that since this is a technical preview, things may change quite rapidly. But here’s how it currently works.

1. We’re leveraging our recent work to [migrate image management to containerd](https://www.docker.com/blog/extending-docker-integration-with-containerd/), as it provides the ability to use both OCI-compatible artifacts and containerd shims.
    
2. We collaborated with [WasmEdge](https://wasmedge.org/) to create a containerd shim. This shim extracts the Wasm module from the OCI artifact and runs it using the WasmEdge runtime.
    
3. We added support to declare the Wasm runtime, which will enable the use of this new shim.
    

![](https://miro.medium.com/v2/resize:fit:616/0*f1936KZKGXA-rIjA.png align="left")

# **Let’s look at an example!**

After installing the preview, we can run the following command to start an example Wasm application:

```plaintext
docker run -dp 8080:8080 --name=wasm-example --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm32 michaelirwin244/wasm-example
```

* `--runtime=io.containerd.wasmedge.v1` - This informs the Docker engine that we want to use the Wasm containerd shim instead of the standard Linux container runtime
    
* `--platform=wasi/wasm32` - This specifies the architecture of the image we want to use. By leveraging a Wasm architecture, we don't need to build separate images for the different architectures. The Wasm runtime will do the final step of converting the Wasm binary to machine instructions.
    

Since a few of the flags might be unfamiliar, let’s explain what they’re doing:

After the image is pulled, the runtime reads the `ENTRYPOINT` of the image to locate and extract the Wasm module. The module is then loaded into the Wasm runtime, started, and networking is configured. We now have a Wasm app running on our machine!

This particular application is a simple web server that says “Hello world!” and echos data back to us. To verify it’s working, let’s first view the logs.

```plaintext
docker logs wasm-example Server is now running
```

We can get the “Hello world” message by either opening to [http://localhost:8080](http://localhost:8080) or using curl.

```plaintext
curl localhost:8080
```

And our response will give us a Hello world message:

```plaintext
Hello world from Rust running with Wasm! Send POST data to /echo to have it echoed back to you
```

To send data to the echo endpoint, we can use curl:

```plaintext
curl localhost:8080/echo -d '{"message":"Hi there"}' -H "Content-type: application/json"
```

And we’ll see the data sent back to use in the response:

```plaintext
{"message":"Hi there"}
```

To remove the application, you can remove it as you do any other Docker service:

```plaintext
docker rm -f wasm-example
```

The new integration means you can run a Wasm application alongside your Linux containers (even with Compose). To learn more, [check out the docs](https://docs.docker.com/desktop/wasm/)!

*Originally published at* [*https://abidmoon.blogspot.com*](https://abidmoon.blogspot.com)*.*
