lxc-create
Create a new Linux container
TLDR
Create a container interactively in /var/lib/lxc/
Create a container in a target directory
Create a container passing options to a template
Display help
SYNOPSIS
lxc-create [-n name] [-f config_file] [-t template] [-o backingstore] [--bdev
PARAMETERS
-n name
The name of the container to create.
-f config_file
Path to a container configuration file.
-t template
The template to use for creating the container (e.g., `ubuntu`, `debian`, `busybox`).
-o backingstore
The backing store to use for the container's root filesystem (e.g., `dir`, `lvm`, `loop`).
--bdev
Block device path to use with the `lvm` backingstore.
--dir
Directory path to use with the `dir` backingstore.
--size
Size of the backing store (e.g., `10G`) when using `lvm` or `loop`.
--fstype
Filesystem type to use for the backing store (e.g., `ext4`, `xfs`).
--lvname
The Logical Volume name when using the `lvm` backingstore.
--vgname
The Volume Group name when using the `lvm` backingstore.
--thinpool
The Thin Pool name when using the `lvm` backingstore with thin provisioning.
--mkdir
Create the directory if it does not already exist when using the `dir` backingstore.
--keep-old
Keep the existing directory if it already exists when using the `dir` backingstore.
--snapshots
Enable snapshots for the container when using the `lvm` backingstore.
--hook
Path to a hook script to execute during container creation.
--logfile
Specify a log file for `lxc-create`.
--logpriority
Specify the log priority (e.g., `ERROR`, `WARN`, `INFO`, `DEBUG`).
-L
List available templates.
-v|--version
Show the version number of `lxc-create`.
-h|--help
Display help information.
DESCRIPTION
The `lxc-create` command is a fundamental tool in the LXC (Linux Containers) ecosystem. It's used to create and initialize a new container. This involves setting up the container's basic file system, configuring networking, and installing a basic operating system. The process is highly customizable. You can specify the container's name, choose a template (which determines the OS distribution to install), and set various configuration options. `lxc-create` can be used interactively, prompting for information, or non-interactively, using command-line parameters. Templates provide a convenient way to quickly set up containers with a specific OS and initial configuration. After the container is created, you can then use other LXC commands like `lxc-start`, `lxc-stop`, and `lxc-console` to manage and interact with the container.
Proper setup and understanding of containerization concepts are required for secure and efficient usage. `lxc-create` simplifies the initial configuration process, allowing you to quickly deploy and test applications in isolated environments. The command is part of the LXC suite, designed to provide a lightweight alternative to full virtualization.
CAVEATS
Using `lxc-create` requires root privileges. The chosen template must be available on your system (usually provided by a package like `lxc-templates`). Incorrect configuration can lead to container startup failures or security vulnerabilities. Ensure your kernel supports LXC features (namespaces, cgroups). Storage configuration (especially LVM) requires careful planning to avoid resource exhaustion.
TEMPLATES
Templates are scripts or packages that automate the process of setting up a container's root filesystem. They often include downloading and installing a base operating system and setting up basic configurations. Popular templates include `ubuntu`, `debian`, `busybox`, and `fedora`.
The templates are typically stored in `/usr/share/lxc/templates/`.
BACKING STORES
Backing stores determine how the container's root filesystem is stored. Common options include `dir` (a directory on the host filesystem), `lvm` (Logical Volume Management), and `loop` (a loopback file).
The choice of backing store can impact performance and resource utilization.
CONFIGURATION FILES
The `-f` option allows you to specify a configuration file that defines the container's settings. This file can override default settings and customize various aspects of the container, such as networking, resource limits, and security settings.
The file format is described in `lxc.conf(5)`.
HISTORY
LXC and `lxc-create` have been evolving since the early 2000s, initially focusing on lightweight virtualization. The command's development has been driven by the increasing demand for containerization technologies, particularly for application deployment and testing. Over time, it has gained features such as support for different backing stores, advanced configuration options, and integration with various Linux distributions. The focus has been on providing a flexible and efficient way to create and manage containers.
SEE ALSO
lxc(1), lxc-start(1), lxc-stop(1), lxc-destroy(1), lxc-console(1)