10.3. 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 Hybrid Server 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.3.1. Using Golden Images¶
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:
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 \ /etc/vz/conf/ve-centos-6-x86_64-mysql-devel.conf-sample
Note
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.
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
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
Note
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
mysql
devel
10.3.1.1. Disabling Golden Images¶
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 tono
in the Virtuozzo Hybrid Server global configuration file. The golden image functionality will be disabled globally.Set the
GOLDEN_IMAGE
option tono
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
containingno
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
containingno
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.3.2. Using Custom 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:
If required, install the default OS template on the hardware node. For example:
yum install centos-7-x86_64-ez
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
.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 \ /vz/template/centos/7/x86_64/config/os/mytmpl
In your template directory, create the file
packages
listing the RPMs you need, one per line. For example,systemd yum
Note
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 thepackages
file for theprlctl enter
command to work on resulting containers.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 Images.
10.3.2.1. Migrating EZ Templates¶
You can migrate OS and application EZ templates between Virtuozzo Hybrid Server servers with the prlsrvctl cttemplate copy
command.
To copy the OS EZ template
centos-7-x86-64
to the remote serverremoteserver.com
, on the local server run:# prlsrvctl cttemplate copy remoteserver.com centos-7-x86-64
To copy an application EZ template, additionally specify the name of the corresponding OS EZ template. For example, to copy the application template
mysql
of the OS templatecentos-7-x86-64
to the remote serverremoteserver.com
, run:# prlsrvctl cttemplate copy remoteserver.com mysql centos-7-x86-64
Note
The specified OS template must be present on the destination server for migration to be successful.
To skip all validation checks, indicate the
--force
option.
The root account is used to log in to the remote server by default, so you will be asked for the root password. You can also provide different credentials (and port) in the format [<user>[:<passwd>]@]<server>[:<port>].
Note that migrating EZ templates always copies them to a remote server. If the source EZ template is not needed after migration, you can manually delete it with the prlsrvctl cttemplate remove
command.
After migration, you can check that the migrated EZ templates are present on the destination server with the prlsrvctl cttemplate list
command:
# prlsrvctl cttemplate list
centos-7-x86_64 os x86_64 yes Centos 7 (for Intel EM64T) Virtuozzo Hybrid Server Template
...
mysql app x86_64 - mysql for Centos 7 (for Intel EM64T) Virtuozzo Hybrid Server
10.3.2.2. 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:
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.3.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:
Download the default OS template source from http://download.openvz.org/virtuozzo/releases/7.0/source/SRPMS.
Edit the template according to your needs, e.g., change OS template parameters, add, change or remove application templates, and such.
Build the RPM from the
.spec
file in a clean environment using standard tools. Do not build more than one template at once.