Use Cases

Creating a Custom Template

20min

How To: Create a Template With Your Own Image

Introduction

You can create a template with your own docker image after reading this guide for most use cases.

Vast instances are currently Linux Docker containers. Many Linux based images should work within Vast. We will be enabling you to use instances that are Windows virtual machines and other kinds of virtual machines soon.

Prerequisites

Setting up Your Custom Template

Step 1 - Navigate to the 'Templates' Section

Once logged in, click on Templates to go to the template section. This is where you can create, manage, and edit templates.

Step 2 - Create a New Template

Click the button + New to create a new template.

Create
Create


Step 3 - Specify the image path/tag of your docker image

In the Image Path Tag, you can add the path/tag of the docker image you wish to use. The Version Tag is where you would set the version.

Image&Tag
Image&Tag


Step 4 - Set Environment Variables

You can use the -e option to set environment variables in the Docker Options field by adding something like:

-e MYVAR1

You can also add environment variables one by one in the Environment Variables section. These entries will automatically sync with the Docker Options field.

Env&Stuff
Env&Stuff


These options will be appended to the docker run command before the docker run command is executed within one of the machines. Similar to how it would be if you were executing "docker run -e MYVAR1 IMAGE[|@DIGEST]" on your local machine.

Step 5 - [Optional] Open Custom Ports

In addition to setting environment variables, you can also open custom ports by adding -p ${HOST_MACHINE_PORT}:${CONTAINER_PORT} to the Docker Options section.

You can also add them to the Ports section. Once more, this will automatically sync with the Docker Options field.

Env&Stuff
Env&Stuff


You can see what's happening inside a container at particular port by finding the public ip address mapped to that container port.

Internally, one of the machine's open ports is mapped to this container port.

You can use ssh to open a ssh connection to the host machine's public ip address. The machine will forward traffic from the host machine's public port to the container port you specified.

You can use a ssh command like the one below.

Text


Step 6 - Pick a Launch Mode

You can choose the jupyter, ssh, or entrypoint launch mode depending on your needs.

Step 7 - Add Starting Bash Commands to On-start Script Section

These commands will be executed as soon the docker container starts, similar to how a bash script be would be executed suppose you created a bash script and added a CMD command in the Dockerfile so Docker would execute this bash script when the container starts.

  1. Before Vast
Text


In this case: CMD specifies the default command to run when the container starts, which is your start.sh script.

  1. In On-Start Script Section With Vast:
Text


You can also try to overwrite existing files built into the image. Make sure you can switch to a user that has write permissions to that particular file.

For example, you can remove all instances of '-sslOnly' in a particular file using sed.

Text


You can also make directories.

Text

Exampleonstart
Exampleonstart


Make sure to append environment variables to /etc/environment file in your on-start section because this makes environment variables available to all users and processes and ensures they are persisted even if your instance/docker container is rebooted. This code snippet will take care of this.

Text


Also make sure to find the image’s ENTRYPOINT or CMD command and call that command at the end of the on-start section. We overwrite that command to set up jupyter/ssh server, etc. under the hood.

Step 8 - Specify Docker Repository Server Name if Necessary

You don't have to specify docker.io as the server name if your repository is Docker Hub. Docker automatically uses docker.io to pull the image if no other registry is specified.

You do have to specify your server name if your repository is something else.

For example,

GitHub Container Registry (GHCR) - Server Name: ghcr.io

Google Container Registry (GCR) - Server Name: gcr.io

Step 9 - Specify Docker Login Username and Password

We will have the same character set for docker login usernames and passwords as Docker soon.

Dockerlogin
Dockerlogin


Step 10 - Specify Template Name and Description

Templatename
Templatename


Step 11- Select the Amount of Disk Space You Want

Diskspace2
Diskspace2


Step 12 - Fill Out Accessibility Section

Choose whether to include ReadMe, make template public, and fill out readme if you desire.

Readme
Readme


Step 13 - Choose to Save And/Or Select Your Template

A new template will be created when you edit, make changes, and save.

Createbuttons
Createbuttons


[Optional] Download/Upload Files/Backup To Cloud Storage

You can download and upload files: Copy Data To/From Instance Storage

You can also backup data to cloud storage: Backup Data to Cloud Storage

Troubleshooting

  • If your image is built for a different CPU architecture than your Vast machine, then it won't work. You can try to find a machine with the required CPU architecture using our GUI or CLI. CLI Documentation Command to Search Offers Using CLI
  • If your image requires a higher CUDA version, then look for a machine with a higher Max CUDA version. The Max CUDA version can be found on the instance card. How to Find Max CUDA version in Instance Card
  • If your image is built to run jupyter, then try running it on a port different than 8080.
  • If you are having issues using ssh launch mode, add your public key to ~/.authorized_keys, install openssh, start openssh when the container starts, and forward the ssh server's port.

Template Examples