container2wasm icon indicating copy to clipboard operation
container2wasm copied to clipboard

Wasi-Browser: Access exposed ports [Question]

Open pierreavn opened this issue 1 year ago • 3 comments

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!

pierreavn avatar May 09 '24 13:05 pierreavn

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 avatar May 10 '24 01:05 ktock

@pierreavn Is this issue solved?

ktock avatar May 19 '24 04:05 ktock