LinuxCommandLibrary

lxc

Manage Linux containers

TLDR

List local containers matching a string. Omit the string to list all local containers

$ lxc list [match_string]
copy

List images matching a string. Omit the string to list all images
$ lxc image list [[remote]:][match_string]
copy

Create a new container from an image
$ lxc init [[remote]:][image] [container]
copy

Start a container
$ lxc start [[remote]:][container]
copy

Stop a container
$ lxc stop [[remote]:][container]
copy

Show detailed info about a container
$ lxc info [[remote]:][container]
copy

Take a snapshot of a container
$ lxc snapshot [[remote]:][container] [snapshot]
copy

Execute a specific command inside a container
$ lxc exec [[remote]:][container] [command]
copy

SYNOPSIS

lxc [global options] command [command options] [arguments]

PARAMETERS

create
    Create a new container.

start
    Start an existing container.

stop
    Stop a running container.

destroy
    Destroy a container.

list
    List existing containers.

info
    Get information about a container.

console
    Attach to the container's console.

exec
    Execute a command inside a container.

file
    Transfer files to or from a container.

snapshot
    Manage container snapshots.

-n, --name NAME
    Specify the container name (used with many subcommands).

-o, --logfile FILE
    Specify a logfile for the lxc command.

-l, --logpriority LEVEL
    Specify a log priority LEVEL (default:ERROR)

DESCRIPTION

LXC is a userspace interface for the Linux kernel containment features. It allows you to easily create and manage system or application containers. These containers are isolated from the host system and each other, providing a lightweight virtualization solution. LXC utilizes cgroups (control groups) and namespaces to achieve isolation, allowing containers to have their own process ID space, network interfaces, mount points, and users. Using LXC, you can run multiple isolated Linux distributions or applications on a single host, improving resource utilization and security.

The LXC command line tools provide a simple and intuitive way to interact with containers. You can use them to create, start, stop, clone, snapshot, and manage containers. The core LXC package provides the `lxc` command which is the main entry point, providing subcommands for specific container management tasks.

CONFIGURATION FILES

Containers are configured using configuration files typically located in `/var/lib/lxc/container_name/config`. These files specify various aspects of the container, such as networking, resource limits, and filesystem mounts. The configuration can be also located under `/etc/lxc/container_name/config`.

NETWORKING

LXC provides several networking options, including bridged networking, NAT, and veth pairs. Bridged networking allows containers to share the host's network interface, while NAT provides a private network for containers. Veth pairs create a virtual Ethernet link between the host and the container.

HISTORY

The Linux Containers project started in 2008 as a set of lightweight virtualization tools. It aimed to provide a user-friendly interface for leveraging the kernel's containerization features. Over time, LXC evolved from simple shell scripts to a comprehensive userspace library and toolset. LXC played a crucial role in the development and popularization of container technology, paving the way for modern container ecosystems like Docker.

SEE ALSO

Copied to clipboard