Skip to content

Create Templates from CLI

Dilshat edited this page Aug 23, 2018 · 4 revisions

This document describes steps that should be performed to build custom Subutai template based on the Debian Stretch base image.

Preparing environment

To build new Subutai template you need following:

  1. Subutai Resource host with the latest version;

  2. Imported debian-stretch image to the system:

# subutai import debian-stretch
INFO[2016-05-02 12:17:56] [Importing debian-stretch]                         
INFO[2016-05-02 12:17:56] [Version: 4.0.0, branch: dev]                
INFO[2016-05-02 12:17:56] Trying local repo, dial tcp 10.10.10.1:8339: getsockopt: no route to host 
INFO[2016-05-02 12:17:57] [Downloading debian-stretch]                       
 73.09 MB / 73.09 MB [==============================================================] 100.00%
INFO[2016-05-02 12:18:13] [Unpacking template debian-stretch]                
INFO[2016-05-02 12:18:15] 
[Installing template debian-stretch]
# 

Preparing container

  1. First of all you need to clone debian-stretch template to container with required name:
# subutai clone debian-stretch nginx
INFO[2016-05-02 12:22:58] [nginx started]
INFO[2016-05-02 12:22:58] [nginx with ID CEDFD8418B76AB41DC61F14E17C6825041D0A834 successfully cloned]
#
  1. Attach container to execute installation commands inside container:*
# subutai attach nginx
(amd64)root@nginx:/# 
  1. Install required software into container:*
(amd64)root@nginx:/# apt update; apt install nginx -y

Service management

Debian Stretch (9.x) uses systemd for service management.

Most of the services installed from Debian repositories provide the correct services that will be started after the container comes up.

But if you need to configure custom service or check that your services active you will need following command:

  • systemctl status nginx shows current status of nginx.service;
  • systemctl start nginx starts nginx.service;
  • systemctl stop nginx stops nginx.service;
  • systemctl enable nginx enables nginx.service auto start after system boot;
  • systemctl disable nginx disables nginx.service auto start after system boot.

Adding custom service to the container

If you need add custom systemd service to the container that was not included after installing your software, you can add systemd unit file that describes required service

Put file with any name with .service suffix like sleep.service to the following directory: /etc/systemd/system/sleep.service

Minimal file should look like following:

[Unit]
Description=MyApp

[Service]
ExecStart=/bin/sleep 9999

[Install]
WantedBy=multi-user.target

After these operations you can use systemctl commands to manipulate your service:

image

Exporting prepared template

To finish template preparation you just need to export your container:

# subutai export nginx -t {cdn-token}
INFO[2016-05-02 12:48:42] [nginx promoted]                             
INFO[2016-05-02 12:48:45] [nginx exported to /var/snap/subutai/common/lxc/tmpdir/nginx-subutai-template_4.0.0_amd64.tar.gz] 
# 

See https://github.com/subutai-io/bazaar/wiki/How-to-obtain-CDN-token

Clone this wiki locally