9.2.3 Creating and Starting a Container


The procedure in this section uses the LXC template script for Oracle Linux (lxc-oracle), which is located in /usr/share/lxc/templates.

An Oracle Linux container requires a minimum of 400 MB of disk space.

To create and start a container:

  1. Create an Oracle Linux 6 container named ol6ctr1 using the lxc-oracle template script.

    [root@host ~]# lxc-create -n ol6ctr1 -B btrfs -t oracle -- --release=6.latest
    lxc-create: No config file specified, using the default config /etc/lxc/default.conf
    Host is OracleServer 6.4
    Create configuration file /container/ol6ctr1/config
    Downloading release 6.latest for x86_64
      yum-metadata-parser.x86_64 0:1.1.2-16.el6                                     
      zlib.x86_64 0:1.2.3-29.el6                                                    

    For LXC version 1.0 and later, you must specify the -B btrfs option if you want to use the snapshot features of btrfs. For more information, see the lxc-create(1) manual page.

    The lxc-create command runs the template script lxc-oracle to create the container in /container/ol6ctr1 with the btrfs subvolume /container/ol6ctr1/rootfs as its root file system. The command then uses yum to install the latest available update of Oracle Linux 6 from Oracle Public Yum. It also writes the container's configuration settings to the file /container/ol6ctr1/config and its fstab file to /container/ol6ctr1/fstab. The default log file for the container is /container/ol6ctr1/ol6ctr1.log.

    You can specify the following template options after the -- option to lxc-create:

    -a | --arch=i386|x86_64

    Specifies the architecture. The default value is the architecture of the host.


    Specifies the file URI of a package repository. You must also use the --arch and --release options to specify the architecture and the release, for example:

    # mount -o loop OracleLinux-R7-GA-Everything-x86_64-dvd.iso /mnt
    # lxc-create -n ol70beta -B btrfs -t oracle -- -R 7.0 -a x86_64 \
    -P | --patch=path

    Patches the rootfs at the specified path.


    Allows you to adjust the values of certain kernel parameters under the /proc hierarchy.

    The container uses a privilege configuration file, which mounts /proc read-only with some exceptions. See Section 9.9, “Configuring Kernel Parameter Settings for Oracle Linux Containers”.

    This option also enables the CAP_SYS_NICE capability, which allows you to set negative nice values (that is, more favored for scheduling) for processes from within the container.

    -R | --release=major.minor

    Specifies the major release number and minor update number of the Oracle release to install. The value of major can be set to 4, 5, 6, or 7. If you specify latest for minor, the latest available release packages for the major release are installed. If the host is running Oracle Linux, the default release is the same as the release installed on the host. Otherwise, the default release is the latest update of Oracle Linux 6.

    -r | --rpms=rpm_name

    Installs the specified RPM in the container.

    -t | --templatefs=rootfs

    Specifies the path to the root file system of an existing system, container, or Oracle VM template that you want to copy. Do not specify this option with any other template option. See Section 9.4, “Creating Additional Containers”.

    -u | --url=repo_URL

    Specifies a yum repository other than Oracle Public Yum. For example, you might want to perform the installation from a local yum server. The repository file in configured in /etc/yum.repos.d in the container's root file system. The default URL is http://public-yum.oracle.com.

  2. If you want to create additional copies of the container in its initial state, create a snapshot of the container's root file system, for example:

    # btrfs subvolume snapshot /container/ol6ctr1/rootfs /container/ol6ctr1/rootfs_snap

    See Chapter 5, The Btrfs File System and Section 9.4, “Creating Additional Containers”.

  3. Start the container ol6ctr1 as a daemon that writes its diagnostic output to a log file other than the default log file.

    [root@host ~]# lxc-start -n ol6ctr1 -d -o /container/ol6ctr1_debug.log -l DEBUG

    If you omit the -d option, the container's console opens in the current shell.

    The following logging levels are available: FATAL, CRIT, WARN, ERROR, NOTICE, INFO, and DEBUG. You can set a logging level for all lxc-* commands.

    If you run the ps -ef --forest command on the host system and the process tree below the lxc-start process shows that the /usr/sbin/sshd and /sbin/mingetty processes have started in the container, you can log in to the container from the host. See Section 9.3, “Logging in to Containers”.