LinuxCommandLibrary

lxc-attach

Execute commands inside a running container

TLDR

Attach to a container

$ sudo lxc-attach [container_name]
copy

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

SYNOPSIS

lxc-attach [-n name] [--clear-env] [--keep-env=variable] [-- as user] [-- group group] [--cwd directory] [-- command]

PARAMETERS

-n name
    Specifies the name of the container to attach to.

--clear-env
    Clear the environment variables before executing the command inside the container.

--keep-env=variable
    Keep the specified environment variable when attaching to the container. Multiple variables can be specified by repeating the option.

--as user
    Execute the command as the specified user inside the container.

--group group
    Execute the command as the specified group inside the container.

--cwd directory
    Execute the command from the specified directory inside the container.

-- command
    Specifies the command to execute inside the container. If no command is specified, a shell is usually started.

DESCRIPTION

The lxc-attach command allows you to execute a command directly within the context of a running LXC container.
This is useful for troubleshooting, managing processes, or running interactive applications inside the container without requiring an SSH connection.
It utilizes the container's namespace, providing a view of the container's filesystem, process list, and network interfaces.
lxc-attach simplifies interacting with containers by providing a direct entry point, making it a powerful tool for container management and development.

CAVEATS

Requires appropriate privileges to access the container's namespace. The command will execute within the container's security context.

SECURITY CONSIDERATIONS

Attaching to a container grants access to its internal environment. Ensure the container is properly secured and that the user executing lxc-attach has the necessary permissions.

SEE ALSO

lxc(1), lxc-console(1), lxc-execute(1)

Copied to clipboard