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"
Share:
5,219

Related videos on Youtube

Leon Straathof
Author by

Leon Straathof

Updated on September 18, 2022

Comments

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

  • Leon Straathof
    Leon Straathof over 8 years
    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?
  • A.B.
    A.B. over 8 years
    I don't understand. In the same way as before. E.g. using -R.
  • A.B.
    A.B. over 8 years
    Answer updated.
  • Leon Straathof
    Leon Straathof over 8 years
    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.
  • A.B.
    A.B. over 8 years
    What's about -R
  • Leon Straathof
    Leon Straathof over 8 years
    I should specify: the reason ... screen -x fails is because I get There are several suitable screens on: followed by a list of sessions. Same with screen -R.
  • A.B.
    A.B. over 8 years
    Perhaps you should ask a new question for this problem. :) seems to be a little bit complicated.
  • Leon Straathof
    Leon Straathof almost 8 years
    There 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
    LUser over 2 years
    @JonathanY. just run script /dev/null and then run screen.