Ubuntu – Working with screen sessions in LXD-managed containers


I have been trying to attach and detach screen sessions in LXD-managed containers; initially, I wasn't able to even start one, but that problem was answered here.

However, being able to start a session, then detach it, isn't sufficient. To work with screen sessions, one must be able to re-attach to a certain session.

I can initiate a session with

lxc exec my-ubuntu -- sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -s /bin/bash"

but then, when I issue

lxc exec my-ubuntu -- sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -x"

either nothing at all happens (I just get another command line) or, if I've issued the first command more than once, I get There are several suitable screens on: followed by a list of sessions, and a suggestion to re-attach to them with "screen [-d] -r [pid.]tty.host". However, that also fails silently. I've also tried to issue

lxc exec my-ubuntu -- sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /bin/bash"

and then screen -x from the resulting terminal, to no avail.

What can I do?

If I use the last command to get a terminal inside my container my-ubuntu, I can initiate screen sessions just typing screen, and detach them with CTRL-a followed by d. However, screen -x then fails silently just as described above, and if I try CTRL-a followed by n from within a session, it reports no other window.

Best Answer