ktock / container2wasm

Container to WASM converter

Home Page:https://ktock.github.io/container2wasm-demo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose a tty to the runtime

rajsite opened this issue · comments

Is there a way to get the equivalent behavior of docker run -it, for example if I wanted to run the docker/doodle containers: https://hub.docker.com/r/docker/doodle/tags

Looks like via the WASI preview 1 layer it wouldn't really be possible today: WebAssembly/WASI#42

What's doable today would be forwarding over telnet / ssh etc: WebAssembly/WASI#161 (comment)

But with WASI preview 2, component model, and wasi-cli there may be early proposals to enable pseudoterminal manipulation: WebAssembly/WASI#161 (comment)

@rajsite Tty is available for the applications running in the container. Maybe you need to switch the your terminal to raw mode to get the raw acccess to it (e.g. stty raw -echo ; wasmtime /out/out.wasm vi ; stty -raw echo). But the terminal size is always 80 x 25 as of now because the emulator can't receive SIGWINCH on WASI. Maybe, if needed, we can at least add a flag to allow specifying the terminal size on container startup.

Reason I was thinking a tty isn't available was when running:

./c2w docker/doodle:halloween halloween.wasm
wasmtime halloween.wasm

I get the following error:

panic: exec: "infocmp": executable file not found in $PATH

goroutine 1 [running]:
main.main()
	/project/halloween.go:276 +0xbe8

I get the above error when I forget to pass -it to docker run, i.e. docker run docker/doodle:halloween vs docker run -it docker/doodle:halloween.

So that's where the original phrasing of the question came from. It's assuming there is something else that the -it flag is doing in docker that isn't duplicated in container2wasm for setting up a tty. My guess is that the app is detecting that a tty is not available and trying to use infocomp to query if terminals are available but infocomp isn't in the container (but maybe doesn't need to be if the terminal gets set-up as it expects).

@rajsite It seems to lack TERM=xterm envvar which docker seems to add by default and this causes the different behaviour. Could you add it manually when starting the container (e.g. by stty raw -echo ; wasmtime --env TERM=xterm /out/out.wasm ; stty -raw echo)?

Seems to work! So cool!

halloween

Does look like this demo could use a configurable terminal size :P Happy Hal!