How to run Wasm module with podman + crun?

608 views Asked by At

I am trying to use podman to run a Wasm module as shown here, but I keep getting the error "Exec format error".

I have a Wasm module named "hellor.wasm" which executes correctly using both wasmer and wasmtime.

I am running podman on Rocky Linux 8:

podman version
Client:       Podman Engine
Version:      4.2.0
API Version:  4.2.0
Go Version:   go1.18.4
Built:        Tue Nov  8 13:34:11 2022
OS/Arch:      linux/amd64

I created this Dockerfile:

FROM scratch
COPY hellor.wasm /
CMD ["/hellor.wasm"]

I then ran buildah with this command:

buildah build --annotation="module.wasm.image/variant=compat" -t wtest5

I then tried to run the module with this podman command:

podman run wtest5:latest
exec /hellor.wasm: exec format error

I then installed the latest version of crun, replacing /usr/bin/runc with the crun binary from https://github.com/containers/crun. However, I still get the same error:

podman run wtest5:latest
# {"msg":"exec container process `/hellor.wasm`: Exec format error","level":"error","time":"2022-12-23T18:43:47.495630Z"}

Is there something else I need to do to enable podman to run Wasm?

1

There are 1 answers

0
Tony Iams On

Solved, thanks to help from the crun developers.

To build crun for wasm, it is first necessary to install wasmedge. These commands worked on Rocky Linux 8:

curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash
source $HOME/.wasmedge/env

Next, crun has to be built using "--with-wasmedge" configure flag (note package dependencies for running on RHEL/CentOS 8):

git clone https://github.com/containers/crun
cd crun
./autogen.sh
./configure --with-wasmedge 
make
sudo make install

Then crun will show that wasm support is installed:

# crun --version
crun version 1.7.2.0.0.0.26-51af
commit: 51af1448f60b69326cf26e726e14b38fcb253943
rundir: /run/user/0/crun
spec: 1.0.0
+SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +WASM:wasmedge +YAJL

For use by podman, replace runc with the new crun:

mv /usr/bin/runc /usr/bin/runc.ORIG
cp /usr/local/bin/crun /usr/bin/runc

Then, podman can run the wasm module:

#podman run wtest6:latest
Hello, world!