41

I'm working with lxc in Ubuntu 12.04, and it's really great. However, I am unable to disconnect from a lxc-console session after I've connected. I read somewhere that Ctrl-aq will disconnect me from the console but it doesn't seem to work.

Should I be running lxc-console via screen instead?

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
robbyt
  • 1,622
  • 3
  • 14
  • 26
  • I have the same issue. If you start a container forgetting the "-d" parameter, there is no way out. Ctrl a q has no effect. The only solution I have found is to login to the console, and do "sudo poweroff", that gets you out. – eos Jun 06 '15 at 22:03
  • you can also do an `lxc-stop` from another shell – Martin Serrano May 25 '16 at 16:58

6 Answers6

58

Yes, Ctrl-aq, should work by default, however no, lxc-console does not actually use screen to accomplish its console behavior. In fact, you might be encountering a conflict if you are using screen since it also uses Ctrl-a as a prefix. If you're inside screen but don't realize it then you'll need to type Ctrl-a a q since the default behavior of screen is that you have to type Ctrl-a a to actually send ^a to the shell running inside of it. You can change the prefix for escape by passing the -e or --escape=PREFIX option to lxc-console.

Also, it appears there may be a bug in lxc-start so that if it immediately goes into console mode when you start the container you can't using Ctrl-a q to escape-- in fact, all the control characters seem to be screwed up and print to the screen instead of behaving the way you expect. One workaround is to run it with the -d or --daemon option so that it doesn't immediately start a console, and the connect to it by hand:

lxc-start -d -n container-name
lxc-console -n container-name
aculich
  • 3,520
  • 1
  • 25
  • 33
  • 1
    Ctrl-a q does not have any effect on a connected console with lxc version 0.9.0 – Jay Taylor Aug 30 '13 at 20:43
  • 5
    if the lxc devs should ever wonder why docker had a billion times higher adoption, this bug is one of the main reasons. – Florian Heigl Aug 14 '16 at 20:43
  • 1
    @FlorianHeigl While I agree with your sentiment about this bug being ugly, the true reasons for that are attitudes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=768073 https://access.redhat.com/articles/1365153 https://access.redhat.com/discussions/2772171 (and numerous other occasions where RedHat responds to "LX(C|D)?" with "No, Docker!" (note that these are top Google results for "LXD Debian", and "LXD Redhat queries"). – Bojan Markovic Feb 27 '18 at 15:51
3

What I did to stop the container

  1. Open a new session.
  2. Login as root.
  3. Check the container status.
  4. lxc-stop -n <name of the container>

This will stop the container.

HBruijn
  • 72,524
  • 21
  • 127
  • 192
Sreenivas
  • 31
  • 1
0

Doesn't it connect via screen? Ctrl-a d should get you out of it.

The Ubuntu LXC page has more information.

El Yobo
  • 926
  • 1
  • 8
  • 11
  • No, this does not work. I've been using screen so that I can disconnect from lxc-console. Also, the link that you posted does not have any information about this problem. – robbyt Aug 06 '12 at 03:02
  • "Detach screen: C-a d or C-a C-d" - https://help.ubuntu.com/community/LXC#Mini_screen_how-to; not sure what to do if that's not working. – El Yobo Aug 06 '12 at 23:34
  • 1
    @ElYobo No, `lxc-console` does not actually use `screen`, it just has similar behavior and by default actually uses a key that conflicts with `screen`'s as [described here](http://serverfault.com/a/438824/93109). – aculich Oct 16 '12 at 08:21
0

An alternative way to login is to just do ssh <ip> instaed of using lxc-console. You could use start it as daemon using lxc-start -d -n <name> and then login using console to get the IP for the first time.

Nishant
  • 265
  • 3
  • 5
  • 11
0

I had a similar issue when working with my Trusty LXC in Xenial-host and after starting the container with lxc-start -F -n CN couldn't get out and back to host when logged out from the container. Also the sudo lxc-ls -fin the host hanged and none of the lxc-stopcommands with -k or -W or --no-lock options worked, so I eventually kill -9'd the container process which worked but afterwards starting the container with lxc-start or lxc-attachdo not work properly, but display errors about lxc_cgfsng and not finding the init pid etc.

See more here: https://github.com/lxc/lxc/issues/1195

OpenITeX
  • 101
  • 1
-6

When you are done working with some application you can usually terminate it witch CTR+C. If that doesn't do the trick, there is always the quit command: CTRL+.

CTRL+D, on the other hand means "END OF FILE", and works usually to stop some program from reading the keyboard. You can log out of regular shell with CTRL+D.