Using Templates¶
Templates can save precious time!
Set up a jail and create a template from it. All packages and preconfigured settings remain available for deployment to new jails within seconds.
Any jail can be converted between jail and template as needed. Essentially, a template is just another jail which has the property template set to yes. The difference is templates are not started by iocage.
Create a template with iocage:
Create a jail:
# iocage create -r 11.0-RELEASE -n mytemplate
.Configure the jail’s networking.
Install packages and/or customize the jail as needed.
Once finished with customization, stop the jail:
# iocage stop mytemplate
.It is recommended to add notes to the jail, so the specific jail customizations are easily remembered:
# iocage set notes="customized PHP,nginx jail" mytemplate
Set the template property on:
# iocage set template=yes mytemplate
.Find the new template with iocage list -t.
Use the created template:
Use iocage create -t to create a new jail from the new template:
# iocage create -t mytemplate -n jailfromtemplate
Find the new jail with iocage list.
Start the jail with
# iocage start jailfromtemplate
.
Done!
Customizing a template:
To make changes to the template, you will need to know whether any existing jails are based on the template. Since modifying the template will require converting it back into a jail, it cannot be the base for any jails.
* No jails based on the template *
Convert the template back into a jail:
iocage set template=no [UUID | NAME].
Start the jail:
iocage start [UUID | NAME].
Use any method you wish to connect to the jail and modify its contents.
Stop the jail:
iocage stop [UUID | NAME].
Convert the jail back into a template:
iocage set template=yes [UUID | NAME].
* Jails based on the template *
This process will create a new template, leaving the existing template and jails unaffected.
Create a ‘thick’ jail from the template, so that it will be independent from the template:
iocage create -T -t [UUID | NAME] -n newtemplate.
Start the jail:
iocage start newtemplate.
Use any method you wish to connect to the jail and modify its contents.
Stop the jail:
iocage stop newtemplate.
Convert the jail into a template:
iocage set template=yes newtemplate.