跳至主要内容

Quick start with Red Hat

In this guide, we will walk you through how to quickly run WasmEdge apps in Fedora / CentOS / Red Hat Linux / OpenShift systems. There is no additional dependencies as the entire development and runtime environments are managed by OpenSift / Podman.

備註

If you are not using OpenShift / Podman, get started here.

We will cover the following examples.

Install

You can use an one-liner dnf command to install WasmEdge, crun and Podman on your Fedora / CentOS / Red Hat Linux system. The WasmEdge Runtime is available as an officially maintained upstream package for Fedora 37 and Red Hat REPL 8 and 9.

dnf install wasmedge crun-wasm podman

Run a standalone WASM app

The Hello world example is a standalone Rust application. Its source code and build instructions are available here.

Use Podman 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 Red Hat supports.

$ podman --runtime /usr/bin/crun-wasm run --platform=wasi/wasm -t --rm docker.io/secondstate/rust-example-hello:latest
Hello WasmEdge!

To learn more about how to create WASM apps in Rust

Run an HTTP server

This example is a standalone HTTP server written in Rust. It demonstrates Rust + WasmEdge as a lightweight stack for microservices. Its source code and build instructions are available here.

Use Podman 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.

$ podman --runtime /usr/bin/crun-wasm run -dp 8080:8080 --platform=wasi/wasm -t --rm docker.io/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

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.

$ podman --runtime /usr/bin/crun-wasm run -dp 8080:8080 --platform=wasi/wasm -t --rm docker.io/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.

Next steps