Wasm workloads (original) (raw)

WebAssembly (Wasm) is a fast, light alternative to Linux and Windows containers. With Docker Desktop, you can now run Wasm workloads side by side with traditional containers.

This page provides information about the ability to run Wasm applications alongside your Linux containers in Docker.

Tip

Learn more about Wasm use cases and tradeoffs in theDocker Wasm technical preview blog post.

Wasm workloads require thecontainerd image storefeature to be turned on. If you’re not already using the containerd image store, then pre-existing images and containers will be inaccessible.

  1. Navigate to Settings in Docker Desktop.
  2. In the General tab, check Use containerd for pulling and storing images.
  3. Go to Features in development and check the Enable Wasm option.
  4. Select Apply & restart to save the settings.
  5. In the confirmation dialog, select Install to install the Wasm runtimes.

Docker Desktop downloads and installs the following runtimes:

Running a Wasm application with docker run

The following docker run command starts a Wasm container on your system:

After running this command, you can visithttp://localhost:8080/ to see the "Hello world" output from this example module.

If you are receiving an error message, see thetroubleshooting section for help.

Note the --runtime and --platform flags used in this command:

Running a Wasm application with Docker Compose

The same application can be run using the following Docker Compose file:

Start the application using the normal Docker Compose commands:

Running a multi-service application with Wasm

Networking works the same as you'd expect with Linux containers, giving you the flexibility to combine Wasm applications with other containerized workloads, such as a database, in a single application stack.

In the following example, the Wasm application leverages a MariaDB database running in a container.

  1. Clone the repository.
  2. Navigate into the cloned project and start the project using Docker Compose.
    If you run docker image ls from another terminal window, you can see the Wasm image in your image store.
    Inspecting the image shows the image has a wasi/wasm platform, a combination of OS and architecture:
  3. Open the URL http://localhost:8090 in a browser and create a few sample orders. All of these are interacting with the Wasm server.
  4. When you're all done, tear everything down by hitting Ctrl+C in the terminal you launched the application.

Building and pushing a Wasm module

  1. Create a Dockerfile that builds your Wasm application.
    Exactly how to do this varies depending on the programming language you use.
  2. In a separate stage in your Dockerfile, extract the module and set it as the ENTRYPOINT.
  3. Build and push the image specifying the wasi/wasm architecture. Buildx makes this easy to do in a single command.

This section contains instructions on how to resolve common issues.

Unknown runtime specified

If you try to run a Wasm container without thecontainerd image store, an error similar to the following displays:

Turn on the containerd featurein Docker Desktop settings and try again.

Failed to start shim: failed to resolve runtime path

If you use an older version of Docker Desktop that doesn't support running Wasm workloads, you will see an error message similar to the following:

Update your Docker Desktop to the latest version and try again.