In this example, we demonstrate how to build a standalone WASM application from the rust application.
If you simply want a wasm bytecode file to test as a container image, you can skip the building process and just download the wasm file here.
If you have not done so already, follow these simple instructions to install Rust and rustwasmc toolchain.
git clone git@github.com:second-state/wasm-learning.git
cd cli/wasi
rustwasmc build
The wasm bytecode application is in pkg/wasi_example_main.wasm
file. You can now publish and use it as a container image.
chmod +x pkg/wasi_example_main.wasm
Create a file called Dockerfile
in the pkg
folder with the following content:
FROM scratch
ADD wasi_example_main.wasm .
CMD ["wasi_example_main.wasm"]
This example uses docker to build image. You can use any other tools to create container image.
Here is an example of creating container image and publishing the wasm bytecode file to the public Docker hub.
sudo docker build -f Dockerfile -t hydai/wasm-wasi-example:latest .
sudo docker push hydai/wasm-wasi-example:latest
Please refer to the section Create container config.