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?
Yes, Ctrl-aq, should work by default, however no,
lxc-console
does not actually usescreen
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 insidescreen
but don't realize it then you'll need to type Ctrl-a a q since the default behavior ofscreen
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 tolxc-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:What I did to stop the container
lxc-stop -n <name of the container>
This will stop the container.
Doesn't it connect via
screen
?Ctrl-a d
should get you out of it.The Ubuntu LXC page has more information.
An alternative way to login is to just do
ssh <ip>
instaed of usinglxc-console
. You could use start it as daemon usinglxc-start -d -n <name>
and then login using console to get the IP for the first time.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 thesudo lxc-ls -f
in the host hanged and none of thelxc-stop
commands 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 withlxc-start
orlxc-attach
do 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
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.