10.2. Creating Customized Containers

If you wish to use custom applications in multiple identical containers, you can create containers with necessary applications already preinstalled and tuned to meet your demands.

Virtuozzo offers several ways to create customized containers with preinstalled applications:

  • From a golden image (an OS EZ template cache with preinstalled application templates).
  • From a custom OS EZ template that specifies a custom application package list.
  • From a custom configuration sample file that specifies custom application EZ templates.

10.2.1. Using Golden Image Functionality

The golden image functionality allows you to preinstall application templates to OS EZ template caches to speed up creating multiple containers based on the same set of OS and application templates. Previously, you could either install application templates to each container after creating it or embed them directly into a custom OS template. Golden image is currently the easiest and fastest way to create containers with preinstalled applications.

The best way to create such a cache is:

  1. Make a custom sample configuration file with information on the OS EZ template to cache and application EZ templates to preinstall. For example:

    # cp /etc/vz/conf/ve-basic.conf-sample \


    If you already have a custom sample configuration file with application EZ templates specified in it, you can reuse it instead of creating a new one.

  2. Add the OS EZ template and application EZ template information to the new configuration file. Each OS and application template name must be preceded by a dot. Multiple consecutive application EZ template names must be separated by white spaces. For example:

    # cd /etc/vz/conf
    # echo OSTEMPLATE=".centos-6-x86_64" >> ve-centos-6-x86_64-mysql-devel.conf-sample
    # echo TEMPLATES=".mysql .devel" >> ve-centos-6-x86_64-mysql-devel.conf-sample
  3. Run the vzpkg create appcache command with your configuration file as an option. For example:

    # vzpkg create appcache --config centos-6-x86_64-mysql-devel


    If the resulting application cache already exists, it will not be recreated and you will see a corresponding message. To recreate an application cache, use the vzpkg update appcache command.

The resulting archive can be found in the /vz/template/cache directory on the hardware node. You can check that it exists and includes necessary application templates with the following command:

# vzpkg list appcache
centos-6-x86_64              2012-07-20 16:51:36
     devel Disabling Golden Image Functionality

The Golden Image functionality is enabled by default in the /etc/sysconfig/vz/vz.conf global configuration file. Should you wish to disable it, do one of the following:

  • Set the GOLDEN_IMAGE option to no in the Virtuozzo global configuration file. The Golden Image functionality will be disabled globally.
  • Set the GOLDEN_IMAGE option to no in the container sample configuration file. The Golden Image functionality will be disabled for commands that use this specific sample configuration file.
  • Create a file named golden_image containing no in the OS EZ template’s configuration directory. The Golden Image functionality will be disabled for this specific OS EZ template.
  • Create a file named golden_image containing no in the application template’s configuration directory. The Golden Image functionality will be disabled for this specific application template, so it will not be preinstalled into any OS EZ template caches.

10.2.2. Using Customized EZ Templates

You can create custom OS and application templates tailored to your needs. In such a template, you only need to specify parameters that differ from those in the default template. All other parameters—that are not explicitly set in the custom template—are inherited from the corresponding default template.

To create a custom template, do the following:

  1. If required, install the default OS template on the hardware node. For example:

    yum install centos-7-x86_64-ez
  2. Create a directory for your template at the location where the default template directory is. For example, for a custom CentOS 7 64-bit template mytmpl, create the directory /vz/template/centos/7/x86_64/config/os/mytmpl.

  3. If you are creating a custom OS template, specify repositories. For example, copy the file mirrorlist from the default template directory to your template directory:

    # cp /vz/template/centos/7/x86_64/config/os/default/mirrorlist \
  4. In your template directory, create the file packages listing the RPMs you need, one per line. For example,



    The minimal list of packages to include in a custom template may vary depending on guest OS. For example, CentOS 7 templates require that systemd be specified in the packages file for the prlctl enter command to work on resulting containers.

  5. Optionally, change more template parameters according to your needs (for a description of parameters, see the next section).

Your custom template is ready. In this example, it is an OS template that contains systemd, yum, and all their prerequisites. You now can create containers based on it. For example:

# prlctl create MyCT --vmtype ct --ostemplate centos-7-x86_64-mytmpl

If you created an application template, you now can add it to the container configuration file as described in Using Golden Image Functionality. EZ Template Configuration Files

All EZ templates are stored in /vz/template, in subdirectories named according to OS name, version, and architecture. For example, /vz/template/centos/7/x86_64. Each template includes a set of configuration files stored in the /config/os/<template_name> subdirectory (OS templates) or the /config/app/<template_name> subdirectory (application templates).

The following files can be in the template configuration subdirectory:

  • ct2vm – Container to virtual machine migration script.
  • description – Detailed information on the EZ template.
  • distribution – OS templates only. The name of the Linux distribution for which the EZ template is created.
  • environment – OS templates only. A list of environment variables set in the form of <key>=<value>.
  • mirrorlist – Links to files with lists of repositories from which the packages in the EZ template are to be downloaded.
  • osrelease – OS templates only. Contains native CentOS 7 distribution kernel version.
  • package_manager – OS templates only. Specifies the packaging system used to handle the EZ template.
  • packages – Contains a list of package names included in the corresponding EZ template.
  • pre-cache, post-cache – OS templates only. Scripts that are executed before and after the packages in the EZ template are installed on the hardware node.
  • pre-install, post-install – Scripts that are executed inside the container before and after the package management transaction.
  • pre-install-hn, post-install-hn – Scripts that are executed on the hardware node before and after the package management transaction.
  • pre-upgrade, post-upgrade – OS templates only. Scripts that are executed before and after updating packages inside the container.
  • pre-remove, post-remove – Scripts that are executed before and after removing the application EZ template or package from the container.
  • release – Contains template release number.
  • repositories – Contains a list of repositories where the packages in the EZ template are stored.
  • summary – A brief summary of the EZ template.
  • upgradable_versions – OS templates only.
  • version – Contains template version number.

10.2.3. Creating Customized EZ Template RPMs

To share a custom EZ template between hardware nodes, you can create an RPM package with it as follows:

  1. Download the default OS template source from http://download.openvz.org/virtuozzo/releases/7.0/source/SRPMS.
  2. Edit the template according to your needs, e.g., change OS template parameters, add, change or remove application templates, and such.
  3. Build the RPM from the .spec file in a clean environment using standard tools. Do not build more than one template at once.