Triton CLI Basic Tutorial

Created by Olaf van der Graaf at 06-12-2017 11:05:35 +0100

In this Triton CLI Basic Tutorial we will go over the setup and installation of Triton CLI, Triton profiles, container creation and container management. You can even use a cloud container with the Ubuntu image, created on our website, to follow this tutorial.

Note: every line that has a '~#' at the start is a command that you need to execute in Linux.

Triton CLI setup

In the following steps we will update the system, install Node.js and update npm in order for Triton CLI to be used correctly. Execute the given commands below:

GENERAL UPDATE 
~# sudo apt-get update 
~# sudo apt-get dist-upgrade 
~# sudo apt-get install -y build-essential
INSTALL NODE.JS TO RUN JAVASCRIPT PROGRAMS 
Node.js is a run-time environment which includes everything you need to execute a program written in Javascript. Almost all Javascript written programs need Node.js to run, including Triton CLI: 
~# curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - 
~# sudo apt-get install -y nodejs
CHECK NODE/NPM VERSION: 
~# node -v 
v8.11.3  
UPDATE NPM: 
~# npm update  
CHECK NPM VERSION 
~# npm -v 
5.6.0
 INSTALL TRITON CLI 
~# sudo npm install --unsafe-perm -g triton
CHECK TRITON CLI VERSION 
~# triton --version 
Triton CLI 6.1.2

It is recommended that you keep Ubuntu, Node.js, npm and Triton CLi up to date in order for them to work properly.

Triton profiles

Prerequisites for a working connection:

1. cloudcontainers account: A cloudcontainers account is needed for storing your Triton account information, billing information and SSH key distribution among Initworks' data centers.

2. ssh key: in order for Triton to connect to your account, you need an SSH key linked to your account. You can add an SSH key on your cloudcontainers website account under 'Hello, [name]' -> 'settings'. Give the key a name and paste the entire public key in the 'Key value' field, like so:

Triton profiles are used to create and 'manage' containers. Your triton profile has a Triton account, which contains the containers. If you delete your Triton profile, you will not lose any containers, you can simply create a new Triton profile and use your Triton account to access your containers.

  • create a new profile with the following command:
CREATING A NEW PROFILE 
~# triton profile create

Explanation of the necessary input:

The input name is your profile name, this can be anything to your liking.

The CloudAPI endpoint URL, is the endpoint URL of Initworks. Use one of the endpoints found on the docker page on the cloudcontainers website. To access this you will need an account on https://my.cloudcontainers.net/#/.

Your account login name is your login name used on https://my.cloudcontainers.net/#/

keyId is the keyId of the SSH key linked to your cloudcontainers account. If you do not have an SSH key yet, you can find out here how to create and add one to your cloudcontainers account.

Continue? No for now. This is only for people who are going to use docker containers. Simply enter 'n'.

  • If you would like to create and use a new profile, execute the previous command first, and then set the new profile with the following command:
SETTING NEW PROFILE 
~# triton profile set [PROFILE NAME]
  • selecting a different a profile

To check what other profiles you have created, you can execute the following command:

GET A LIST OF ALL PROFILES
~# triton profile list
NAME    CURR  ACCOUNT          USER  URL
cloud1  *     [TRITON ACCOUNT] -     https://office1-cloudapi.dev.mc.initworks.net 
clud2         [TRITON ACCOUNT] -     https://office1-cloudapi.dev.mc.initworks.net 

If you have another profile you would like to select, execute the command below. If you do not have another one, simply create a new profile and then follow the command below:

SELECTING A DIFFERENT PROFILE 
~# triton profile set [PROFILE YOU WISH TO SET] 
Profile set to "[NEW PROFILE]"
  • deleting a profile

Deleting a profile will not result in the loss of data. Containers are linked to your Triton account, not to your Triton profiles.

DELETING A PROFILE 
~# triton profile delete [PROFILE YOU WISH TO DELETE] 
Delete profile "[PROFILE]"? 
[y/n] [TYPE y OR n] 
Deleted profile "[PROFILE]"


Creating containers with Triton CLI

Containers are the main topic of this tutorial and many other tutorials on initworks.com. If you wish to learn more on the subject of cloud containers, more information can be found here.

the following is an example of creating a container:

CREATING A NEW CONTAINER WITH TRITON COMMAND 
~# triton instance create -w --name=triton_cli_container_1 ubuntu-16.04_120@1.2.0 nrm_2g_30g

explanation of the command tags:

The option -w will let you wait for the creation to complete and shows the status of the completion.

The option --name is the option to name your container. If you do not name your container, a name will be generated server-side. 

The argument ubuntu-16.04_120@1.2.0 will be the image of the contianer. To get a list of all the images you can choose, execute the following command:

LIST ALL POSSIBLE IMAGES 
~# triton image list 

The argument nrm_2g_30g will be the package of the container. You can learn more concerning packages and their pricing here. To get a list of all packages you can choose, execute the following command:

LIST ALL POSSIBLE IMAGES 
~# triton packages list -o shortid,name,memory,swap,disk,description

Starting your container

The 'start' container command is not necessary after creating a container, but manually starting a container can be done by the following command:

If you do not wish to wait and instead want to continue doing other tasks, remove the '-w' from the command
STARTING A CONTAINER: 
~# triton instance start -w [CONTAINER NAME] 
Start instance [CONTAINER NAME] ([CONTAINER ID])

Stopping your container

Stopping your container can be done with the following command and will result in the remote host cancelling all active connections: 

If you do not wish to wait and instead want to continue doing other tasks, remove the '-w' from the command
STOPPING A CONTAINER: 
~# triton instance stop -w [CONTAINER NAME] 
Stop instance [CONTAINER NAME] ([CONTAINER ID])

Rebooting your container

If you would like to reboot your container, this can be done with the following command: 

If you do not wish to wait and instead want to continue doing other tasks, remove the '-w' from the command
Note: any connection to the container will be closed by the remote host if a reboot is executed
REBOOTING A CONTAINER 
~# triton instance -w reboot [CONTAINER NAME] 
Reboot instance [CONTAINER NAME]

Deleting/Destroying your container

Running containers which are not being used may result in unwanted costs, thus you may want to destroy a container. It is advised that you make absolutely sure that no operations are dependent on the functionality of the container you wish to destroy. If you are sure that the container can be destroyed, then a container can be destroyed with the following command:

Warning: there is no 'are you sure?' question after you execute the commmand. Your container will immediately be deleted after the command is executed.

If you do not wish to wait and instead want to continue doing other tasks, remove the '-w' from the command
DESTROYING A CONTAINER 
~# triton instance delete -w [CONTAINER NAME] 
Delete instance [CONTAINER NAME] ([CONTAINER ID])


Function Help

If you want some more information concerning a function, simply  type the 'help' tag before your function of choice, like so:

SOME EXAMPLES FOR USING A HELP TAG 
~# triton help instance 
~# triton instance help rename 
~# triton instance help resize


Find out more about using containers on the Triton CLI Advanced Tutorial.

Comments

Comments are turned off.