Instances Help
If you use the "custom command" option, then your command will run automatically when the instance starts up. However, if you are using an SSH instance, there is no default startup command. You can put startup commands in "/root/onstart.sh". This startup script will be found and run automatically on container startup.
Every instance offer on the Create page has a Max Duration. When you accept an offer and create an instance, this Max Duration becomes the instance lifetime and begins ticking down. When the lifetime expires, the instance is automatically stopped. The host can extend the contract, which will add more lifetime to your instance, or they may not - it's up to them. Assume your instance will be lost once the lifetime expires; copy out any important data before then.
Use the -e docker syntax in the docker create/run options. For example, to set the env variables TZC to UTC and TASKID to "TEST":
Any environment variables you set will be visible only to your onstart script (or your entrypoint for entrypoint launch mode). When using the SSH or Jupyter launch modes, your env variables will not be visible inside your SSH/tmux/Jupyter session by default. To make custom environment variables visible to the shell, you need to export them to /etc/environment.
Add something like the following to the end of your onstart to export any env variables containing an underscore '_':
Or to export all env variables:
Environment variables can also be set in the User Account settings page, in which case the env variables will be injected into every container onstart.
How can I get the instance ID from within the container? The environment variable VAST_CONTAINERLABEL is defined in the container. Ex:
A special instance api key should already be installed in your container. You can just install the vastai CLI and use the stop command:
Then test it by starting the instance (which is a no-op as the instance is already running):
If that works then you can stop the instance as well:
If $CONTAINER_ID is not defined check your environment variables using the 'env' command. If you are missing the predefined env variables from an ssh session you may need to add a command to export them to /etc/environment (see above).
If you don't have the instance api key for whatever reason, you can also generate it. First run the following from inside the instance to create a special per instance api key and save it in the appropriate location:
Then install the CLI with pip or download latest from github:
Vast currently does not currently support Docker within Docker due to security constraints. You will need to launch each docker container on a separate instance.