ktock / container2wasm

Container to WASM converter
https://ktock.github.io/container2wasm-demo/
Apache License 2.0
1.97k stars 72 forks source link

Wasi-Browser: Access exposed ports [Question] #272

Open pierreavn opened 3 months ago

pierreavn commented 3 months ago

Thanks again for this great project! I'm trying to convert a web server container into wasm then run it in browser with wasi-browser. The container is exposing an http port, but unfortunately I am not able access it.

I've tried to add ˋEXPOSEˋ rule in Dockerfile, and to use port socket binding and port mapping in c2w-net to host port. Looking for GVisor networking, logs tell that connection is refused.

Do you have any idea or configuration to access exposed port, from c2w-net port mapping or directly from JS?

Thanks!

ktock commented 3 months ago

This looks like VM mac address and/or the one registered to c2w-net don't match.

If you can see the VM's mac address (currently it's assigned a random value), you need to pass that mac address to c2w-net via -mac flag. Or, you can patch worker.js to simply disable the random assigning of the mac address.

--- a/examples/wasi-browser/htdocs/worker.js
+++ b/examples/wasi-browser/htdocs/worker.js
@@ -18,7 +18,7 @@ onmessage = (msg) => {
         resp['arrayBuffer']().then((wasm) => {
             if (netParam) {
                 if (netParam.mode == 'delegate') {
-                    args = ['arg0', '--net=socket', '--mac', genmac()];
+                    args = ['arg0', '--net=socket'];
                 } else if (netParam.mode == 'browser') {
                     recvCert().then((cert) => {
                         var certDir = getCertDir(cert);
ktock commented 3 months ago

@pierreavn Is this issue solved?