LinuxCommandLibrary

lxc-console

Access the console of a container

TLDR

Start a console in a container

$ agetty [[-L|--local-line]] [38400] tty1
copy

Connect to an lxc console
$ sudo lxc-console [container_name]
copy

Exit lxc-console
$ <Ctrl a><q>
copy

Display help
$ lxc-console [[-?|--help]]
copy

SYNOPSIS

lxc-console [-n name] [-t tty_number] [-s]

PARAMETERS

-n name
    Specify the name of the container to connect to. This is a mandatory argument.

-t tty_number
    Specify the TTY number to use. Defaults to 0 if not specified. Useful for connecting to specific TTYs within the container.

-s
    Disable line buffering. This is useful for applications that require character-by-character input.

DESCRIPTION

The `lxc-console` command allows you to attach to the console of a running LXC container. This provides direct access to the container's primary input/output, typically a virtual terminal. It's useful for debugging, system administration, or directly interacting with applications running inside the container.

When attached, the console becomes the primary input and output device for the container's init process. This means you can log in, execute commands, and interact with the container as if you were directly logged in to a physical terminal. Detaching from the console typically involves a specific key sequence (usually Ctrl+a followed by q).

Consider using other tools like `lxc-attach` for general command execution within a container, as `lxc-console` is specifically designed for console access.

CAVEATS

Requires root privileges to execute. The container must be running for `lxc-console` to work. The key sequence to detach from the console might vary depending on the container's configuration.

DETACHING FROM THE CONSOLE

The default detach sequence is Ctrl+a q. Some systems or configurations might use a different detach sequence. Check the container's configuration for specific detach instructions.

TROUBLESHOOTING

If you encounter issues connecting to the console, ensure the container is running and that you have the necessary permissions. Check the LXC logs for any error messages. Ensure the container has a working getty process or similar console service configured.

SEE ALSO

lxc-attach(1), lxc-execute(1), lxc-start(1), lxc-stop(1)

Copied to clipboard