6

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 from ssh, but I couldn't apply the suggested solution to my case.

7

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"
9
  • Terrific. 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? Jan 2 '16 at 19:40
  • I don't understand. In the same way as before. E.g. using -R.
    – A.B.
    Jan 2 '16 at 19:42
  • Answer updated.
    – A.B.
    Jan 2 '16 at 19:45
  • Well, I would normally do screen -x, but trying lxc exec my-ubuntu -- sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -x doesn't work, and neither does lxc exec my-ubuntu -- sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -r <pid>.tty.my-ubuntu". Nor can I do screen -x from within bash in the container. Jan 2 '16 at 19:48
  • What's about -R
    – A.B.
    Jan 2 '16 at 19:51
-1

For me, the simple solution was to start screen on the host instead of in the container.

user@localhost:~$ screen
user@localhost:~$ lxc-attach -n yourcontainer
root@container:~# ./start-gameserver.sh
root@container:~# #Use "Ctrl+A:sessionname mygame<Enter>" to set a screen name
root@container:~# #and use the usual "Ctrl+A,D" to disconnect from screen
user@localhost:~$ screen -ls
There is a screen on:
    25418.mygame    (04/15/2019 11:41:56 PM)    (Detached)
user@localhost:~$ screen -r mygame
root@container:~# #etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.