The easiest way to get started with Linux containers is to download a prebuilt distribution in a privileged container. The lxc-create command creates a base container structure and can populate it with a predefined Linux distribution. The syntax of the lxc-create command is as follows:
lxc-create -n NAME -t TYPE
The -n option defines a name for this container. This name will be used to identify this container when it is started, stopped, or reconfigured.
The -t option defines the template to be used to create this container. The type download connects your system to a repository of prebuilt containers and prompts you for the container to download.
This is an easy way to experiment with other distributions or create an application that needs a distribution other than the host's Linux distribution:
$ sudo lxc-create -t download -n ContainerName
The download template retrieves a list of the available predefined containers from the Internet and populates the container from the network archive. The create command provides a list of the available containers and then prompts for the Distribution, Release, and Architecture. You can only run a container if your hardware supports this Architecture. You cannot run an Arm container if your system has an Intel CPU, but you can run a 32-bit i386 container on a system with a 64-bit Intel CPU:
$ sudo lxc-create -t download -n ubuntuContainer ... ubuntu zesty armhf default 20170225_03:49 ubuntu zesty i386 default 20170225_03:49 ubuntu zesty powerpc default 20170225_03:49 ubuntu zesty ppc64el default 20170225_03:49 ubuntu zesty s390x default 20170225_03:49 --- Distribution: ubuntu Release: trusty Architecture: i386 Downloading the image index Downloading the rootfs Downloading the metadata The image cache is now ready Unpacking the rootfs --- You just created an Ubuntu container (release=trusty, arch=i386, variant=default) To enable sshd, run: apt-get install openssh-server For security reason, container images ship without user accounts and without a root password. Use lxc-attach or chroot directly into the rootfs to set a root password or create user accounts.
You can create a container based on your current distribution by selecting a template that matches the current installation. The templates are defined in /usr/share/lxc/templates:
# ls /usr/share/lxc/templates
lxc-busybox lxc-debian lxc-download ...
To create a container for your current distribution, select the appropriate template and run the lxc-create command. The download process and installation takes several minutes. The following example skips most of the installation and configuration messages:
$ cat /etc/issue Debian GNU/Linux 8 $ sudo lxc-create -t debian -n debianContainer debootstrap is /usr/sbin/debootstrap Checking cache download in /var/cache/lxc/debian/rootfs-jessie-i386 ... Downloading debian minimal ... I: Retrieving Release I: Retrieving Release.gpg I: Checking Release signature I: Valid Release signature (key id 75DDC3C4A499F1A18CB5F3C8CBF8D6FD518E17E1) ... I: Retrieving Packages I: Validating Packages I: Checking component main on http://http.debian.net/debian... I: Retrieving acl 2.2.52-2 I: Validating acl 2.2.52-2 I: Retrieving libacl1 2.2.52-2 I: Validating libacl1 2.2.52-2 I: Configuring libc-bin... I: Configuring systemd... I: Base system installed successfully. Current default time zone: 'America/New_York' Local time is now: Sun Feb 26 11:38:38 EST 2017. Universal Time is now: Sun Feb 26 16:38:38 UTC 2017. Root password is 'W+IkcKkk', please change !
The preceding command populates the new container from the repositories defined in your package manager. Before you can use a container, you must start it.