container2wasm icon indicating copy to clipboard operation
container2wasm copied to clipboard

Expose a tty to the runtime

Open rajsite opened this issue 2 years ago • 5 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

rajsite avatar Oct 05 '23 16:10 rajsite

Looks like via the WASI preview 1 layer it wouldn't really be possible today: https://github.com/WebAssembly/WASI/issues/42

What's doable today would be forwarding over telnet / ssh etc: https://github.com/WebAssembly/WASI/issues/161#issuecomment-559610967

But with WASI preview 2, component model, and wasi-cli there may be early proposals to enable pseudoterminal manipulation: https://github.com/WebAssembly/WASI/issues/161#issuecomment-1644662029

rajsite avatar Oct 05 '23 23:10 rajsite

@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.

ktock avatar Oct 06 '23 01:10 ktock

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 avatar Oct 06 '23 17:10 rajsite

@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)?

ktock avatar Oct 07 '23 03:10 ktock

Seems to work! So cool!

halloween

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

rajsite avatar Oct 09 '23 04:10 rajsite