Start a screen session inside LXD-managed container
5,219
For LXD using
lxc exec my-ubuntu -- sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -s /bin/bash"
or
lxc exec my-ubuntu -- sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -x"
or with any other screen
switch.
The same for Docker ;)
docker run -it my-ubuntu sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -s /bin/bash"
Related videos on Youtube
Author by
Leon Straathof
Updated on September 18, 2022Comments
-
Leon Straathof over 1 year
I'd like to start a
screen
session inside an LXD-managed container so that I could detach running processes and maybe re-attach in the future when I want to check on their status.I tried to attach to the container running
$ lxc exec my-ubuntu -- /bin/bash
and then start a session with
screen -x
, but I get the following error:Must be connected to a terminal.
I can see that many people have had a similar problem when trying to initiate
screen
fromssh
, but I couldn't apply the suggested solution to my case. -
Leon Straathof over 8 yearsTerrific. But how can I then work with
screen
the way I normally do, monitor which sessions are running and re-attach to a specific one? -
A.B. over 8 yearsI don't understand. In the same way as before. E.g. using
-R
. -
A.B. over 8 yearsAnswer updated.
-
Leon Straathof over 8 yearsWell, I would normally do
screen -x
, but tryinglxc exec my-ubuntu -- sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -x
doesn't work, and neither doeslxc exec my-ubuntu -- sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -r <pid>.tty.my-ubuntu"
. Nor can I doscreen -x
from within bash in the container. -
A.B. over 8 yearsWhat's about
-R
-
Leon Straathof over 8 yearsI should specify: the reason
... screen -x
fails is because I getThere are several suitable screens on:
followed by a list of sessions. Same withscreen -R
. -
A.B. over 8 yearsPerhaps you should ask a new question for this problem. :) seems to be a little bit complicated.
-
Leon Straathof almost 8 yearsThere aren't any answers there, but I'd like to mention that I did open a new question regarding this issue here. I also suggested a walk-around on that question.
-
LUser over 2 years@JonathanY. just run script /dev/null and then run screen.