LXC provides OS templates for the most popular Linux distributions; Debian, Ubuntu, Centos, Fedora etc.
These templates are customised to operate in a container environment.
To create a container
lxc-create -n mycontainer -t debian
n - container name - any name you want
t - template name for the container OS ie debian, ubuntu etc
You may also specify the architecture. The default, when left unspecified is amd64
lxc-create -n mycontainer -t debian -- -a amd64
To see a list of container OS templates available for use in your LXC installation (depending on where you distribution installs LXC, it could also be in '/usr/share/lxc' so check)
ls /usr/local/share/lxc/templates/
lxc-alpine lxc-centos lxc-fedora lxc-oracle lxc-ubuntu-cloud lxc-altlinux lxc-cirros lxc-gentoo lxc-plamo lxc-archlinux lxc-debian lxc-openmandriva lxc-sshd lxc-busybox lxc-download lxc-opensuse lxc-ubuntu
You can also use a special type of container OS template called 'download'. This downloads updated container OS templates from the LXC linuxcontainer.org server.
root@debian:~# lxc-create -t download -n test Setting up the GPG keyring Downloading the image index --- DIST RELEASE ARCH VARIANT BUILD --- centos 6 amd64 default 20140816_02:16 centos 6 i386 default 20140816_02:16 centos 7 amd64 default 20140814_02:16 debian jessie amd64 default 20140815_22:42 debian jessie armel default 20140815_22:42 debian jessie armhf default 20140815_22:42 debian jessie i386 default 20140815_22:42 debian sid amd64 default 20140815_22:42 debian sid armel default 20140815_22:42 debian sid armhf default 20140815_22:42 debian sid i386 default 20140815_22:42 debian wheezy amd64 default 20140815_22:42 debian wheezy armel default 20140815_22:42 debian wheezy armhf default 20140815_22:42 debian wheezy i386 default 20140815_22:42 fedora 19 amd64 default 20140814_01:27 fedora 19 armhf default 20140814_01:27 fedora 19 i386 default 20140813_01:27 fedora 20 amd64 default 20140814_01:27 fedora 20 armhf default 20140814_01:27 fedora 20 i386 default 20140814_01:27 gentoo current amd64 default 20140814_14:12 gentoo current armhf default 20140814_14:12 gentoo current i386 default 20140814_14:12 oracle 6.5 amd64 default 20140816_00:13 oracle 6.5 i386 default 20140816_00:13 plamo 5.x amd64 default 20140730_15:47 plamo 5.x i386 default 20140730_15:47 ubuntu lucid amd64 default 20140816_03:49 ubuntu lucid i386 default 20140816_03:49 ubuntu precise amd64 default 20140816_03:49 ubuntu precise armel default 20140816_03:49 ubuntu precise armhf default 20140816_03:49 ubuntu precise i386 default 20140816_03:49 ubuntu trusty amd64 default 20140816_03:49 ubuntu trusty arm64 default 20140816_03:49 ubuntu trusty armhf default 20140816_03:49 ubuntu trusty i386 default 20140816_03:49 ubuntu trusty ppc64el default 20140816_03:49 ubuntu utopic amd64 default 20140816_03:49 ubuntu utopic arm64 default 20140816_03:49 ubuntu utopic armhf default 20140816_03:49 ubuntu utopic i386 default 20140816_03:49 ubuntu utopic ppc64el default 20140816_03:49
We cover the use of 'download' template in the LXC advanced guide. For now let's use locally available OS templates to create containers. Once you enter the create command LXC will download the container OS as per the template selected, setup the container and give you the default login credentials.
This typically takes 2-5 minutes depending on your internet connection speed. Once downloaded, container OS's are cached locally for reuse so the next time you create a container with the same OS it will not be downloaded again.
LXC containers once downloaded are stored as individual folders in '/var/lib/lxc'. The individual container folder typically has 3 files; config is the container configuration file, rootfs is the container OS directory and fstab, which is used to mount host directories in the containers.
So now that you have a shiny new container it's time to start it.
lxc-start -n mycontainer -d
The -d option starts the container as a daemon and returns you to the shell. Without the -d option you can see the container boot in the terminal and eventually give you a login screen.
You can't exit this mode without powering off the container at which point you will be dropped back to your terminal so the -d option is the preferred way to start containers.
If you installed the package from the Flockport repo the container will be setup with networking and you can get its IP by running:
lxc-ls -f
lxc-ls gives your information about containers.
Now you can either access your container over ssh or by using LXC tools.
lxc-attach -n mycontainer
-n - containername
lxc-attach will drop you into the container root shell.
You can also use ssh or lxc-console tool to log in to your container.
ssh user@containerip
lxc-console -n containername
Now that you are in the container it's just like being in another OS. You can install apps etc. To exit the container and return to your shell just type exit.
If you are using lxc-console you need to use ctrl+a+q to return to your terminal. To poweroff the container type poweroff or halt.
Here is a list of the LXC commands available
lxc-config lxc-console lxc-info lxc-stop lxc-attach lxc-create lxc-ls lxc-unfreeze lxc-autostart lxc-destroy lxc-monitor lxc-unshare lxc-cgroup lxc-device lxc-snapshot lxc-usernsexec lxc-checkconfig lxc-execute lxc-start lxc-wait lxc-clone lxc-freeze lxc-start-ephemeral
Continue to Part II of the Getting started with LXC Guide
The second part of the guide will cover more advanced LXC functions.