This is a quick overview of basic LXC commands used to manage a container. LXC containers behave like lightweight VMs.
To create a container use the lxc-create command.
lxc-create -t download -n c1
The -t flag is used to specify a container template and the -n flag the name of the container to be created. In this case we are specifying the 'download' template that lets us choose from a list of base OS images.
Once you run this command you will get a list of base OS images in the terminal. Once you select a specific base OS image its downloaded and saved in the /var/lib/lxc folder under the name provided by the -n flag.
Once the container is downloaded you can start it with the lxc-start command. When using LXC commands the -n flag to specify the container name.
lxc-start -n c1
This will start the container c1. Once a container is started you can get detailed information on it with the lxc-info command.
lxc-info -n c1
This will list details on the container including its IP address, cpu, memory usage etc.
You can also get an overview of all running containers on your host with the lxc-ls command.
lxc-ls
This will list all running containers on the system. Once a container is running you can access it with the lxc-attach command.
lxc-attach -n c1
This will drop you into a terminal in the container. You can now install apps and run commands as you would on a VM or any host.
To exit the container simply use the 'exit' command. That will drop you back to your host.
You can stop the container with the lxc-stop command.
lxc-stop -n c1
This will stop the c1 container.
You can create container clones and snapshots with the lxc-copy command.
lxc-copy -n c1 -N c2
This will make a copy of c1 container as c2. Incase you are using a btrfs or zfs file system a subvolume clone will be created. On an ext4 filesystem a normal copy will be made.
To make a snapshot use the -s flag. Note: This only works if you system supports overlayfs.
lxc-copy -s -n c1 -N c2
This will create an overlay snapshot of c1 as c2.