Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach xterm.js to Docker container

Tags:

docker

xtermjs

I'm trying to add a terminal to a web application with xterm.js and its 'attach' addon. I'd like to just have a process running in a Docker container, and then attach the xterm instance to stdin/stdout for the container. The example for the attach addon indicates that this should be straightforward using the websocket interface for container attachment with docker.

I haven't yet been able to do this successfully, but it's possible that it's purely a problem with my local configuration. A github issue for xterm.js leaves it a bit ambiguous whether this should actually work now, based on changes to the docker API. Has anyone had success with this using a modern version of docker?

like image 228
the_el_jefe Avatar asked Aug 12 '26 02:08

the_el_jefe


1 Answers

It was a docker configuration problem on my side...

Apparently the attach addon (and anything else that would try to attach with a websocket, e.g. docker-py) does not work with the default dockerd socket (/var/run/docker.sock), so you have to redirect from another port or run the docker daemon from a tcp socket instead of the unix one. You can do this with the socat tool:

socat TCP-LISTEN:2376,reuseaddr,fork UNIX-CLIENT:/var/run/docker.sock 
like image 80
the_el_jefe Avatar answered Aug 16 '26 01:08

the_el_jefe