Quick start with Docker
In this guide, we will walk you through how to quickly run WasmEdge apps in Docker Desktop. There is no additional dependencies as the entire development and runtime environments are managed by Docker Desktop.
If you are not using Docker Desktop, get started here.
We will cover the following examples.
In this quick start guide, we cover how to run WASM container apps using Docker commands. If you are interested in how to build, publish, and compose WASM container apps from source code, check out the Docker + wasm chapter.
Prerequisite
You must have Docker Desktop 4.15+ installed. Make sure you have turned on the containerd image store feature in your Docker Desktop.
Run a standalone WASM app
The Hello world example is a standalone Rust application. Its source code and build instructions are available here.
Use Docker to run the containerized WASM app. The WASM container image is stored in Docker Hub, and its image size is only 500KB. This image can run on any OS and CPU platform Docker supports.
$ docker run --rm --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm secondstate/rust-example-hello:latest
Hello WasmEdge!
To learn more about how to create WASM apps in Rust
- Basic Rust examples for WasmEdge
- Rust developer guides
- WASI-NN with PyTorch, OpenVINO, or Tensorflow Lite backends
- HTTP and HTTPS client
- MySQL database client
- Redis client
- Kafka client
Run an HTTP server
This example is a standalone HTTP server written in Rust. It demonstrates that Rust + WasmEdge as a lightweight stack for microservices. Its source code and build instructions are available here.
Use Docker to pull the container image (around 800KB) from Docker Hub and then run it in a WasmEdge container. The container starts as a server. Note how we map the container's port 8080 to the local host's port 8080 so that the server becomes accessible from outside of the WASM container.
$ docker run -dp 8080:8080 --rm --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm secondstate/rust-example-server:latest
Listening on http://0.0.0.0:8080
From another terminal window, do the following.
$ curl http://localhost:8080/
Try POSTing data to /echo such as: `curl localhost:8080/echo -XPOST -d 'hello world'`
$ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge"
Hello WasmEdge
To learn more about how to create WASM services in Rust
- Rust developer guides
- HTTP application examples
- Database application examples
- Lightweight microservices in Rust and WasmEdge
Run a JavaScript-based server
This example is a standalone HTTP server written in JavaScript using the node.js API. It demonstrates WasmEdge as a lightweight runtime for zero-dependency and portable node.js applications. Its source code is available here.
$ docker run -dp 8080:8080 --rm --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm secondstate/node-example-server:latest
... ...
From another terminal window, do the following.
$ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge"
Hello WasmEdge
To learn more about how to run JavaScript apps in WasmEdge.
- The WasmEdge QuickJS runtime
- AI inference application examples
- Web service client examples with fetch()
Next steps
- Learn more about building and managing WASM containers in Docker
- Basic Rust examples for WasmEdge
- Use Docker Compose to build and Rust-based microservices
- WasmEdge / MySQL / Nginx - Sample Wasm-based web application with a static HTML frontend, using a MySQL (MariaDB) database. The frontend connects to a WASM microservice written in Rust, that runs using the WasmEdge runtime.
- WasmEdge / Kafka / MySQL - Sample Wasm-based microservice that subscribes to a Kafka (Redpanda) queue topic, and transforms and saves any incoming message into a MySQL (MariaDB) database.
- Write WASM apps in your favorite languages, like Rust, C/C++, JavaScript, Go, and many other languages.