How Networking Works
Vast.ai docker instances have full internet access, but generally do not have unique IP addresses. Instances can have public open ports, but as IP addresses are shared across machines/instances the public external ports are partitioned somewhat randomly. In essence each docker instance gets a fraction of a public IP address based on a subset of ports. Each open internal port (such as 22 or 8080 etc) is mapped to a random external port on the machine’s (usually shared) public IP address. Selecting the ssh launch mode will open and use port 22 internal by default, whereas jupyter will open and use port 8080 (in addition to 22 for ssh).Opening Custom Ports
There are several ways to open additional application ports:There is currently a limit of 64 total open ports per container/instance.
Using Docker Options
You can open custom ports for any docker image using -p arguments in the docker create/run options box in the image config editor pop-up menu. To open ports 8081 (tcp) and 8082 udp, use something like this:Text
- Ports exposed through EXPOSE commands in the docker image
- Ports 22 or 8080 which may be opened automatically for SSH or Jupyter
Using EXPOSE in Dockerfile
Any EXPOSE commands in your docker image will be automatically mapped to port requests.Finding Your Mapped Ports
After the instance has loaded, you can find the corresponding external public IP by opening the IP Port Info pop-up (button on top of the instance) and then looking for the external port which maps to your internal port. It will have a format of PUBLIC_IP -> INTERNAL_PORT. For example:Text
Testing Your Ports
We strongly recommend you test your port mapping. You can quickly test your port mapping with a simple command to start a minimal web server inside the instance:Text
Identity Ports
In some cases you may need an identity port map like 32001:32001 where external and internal ports are the same. For this just use an out-of-range port above 70000:Text
$VAST_TCP_PORT_70000
Port Environment Variables
Our system predefines environment variables for port mappings that you can use:Default Ports
- VAST_TCP_PORT_22: The external public TCP port that maps to internal port 22 (ssh)
- VAST_TCP_PORT_8080: The external public TCP port that maps to internal port 8080 (jupyter)
Custom Ports
For each internal TCP port request:- VAST_TCP_PORT_X: The external public TCP port that maps to internal port X
- VAST_UDP_PORT_X: The external public UDP port that maps to internal port X
Special Environment Variables for UI
You can use special environment variables to control the Vast.ai interface:OPEN_BUTTON_PORT
Set this to map the open button on the instance panel to a specific (external) port corresponding to the specified internal port.Text
JUPYTER_PORT
Use this to control the jupyter button. Set this to your internal jupyter port and the UI will map the jupyter button to open jupyter on the corresponding IP in a new tab.Text
JUPYTER_TOKEN
Use this to control the jupyter button. Set this to your jupyter token and the UI will map the jupyter button to open jupyter using the corresponding JUPYTER_TOKEN in a new tab.Text
Docker Create Options
You can currently set 3 types of docker create/run options in the GUI and CLI:- Environment variables:
-e JUPYTER_DIR=/ -e TEST=OK
- Hostname:
-h billybob
- Ports:
-p 8081:8081 -p 8082:8082/udp -p 70000:70000
Best Practices
- Test your ports: Always verify port mappings work after instance creation
- Use identity ports sparingly: Only when absolutely necessary (ports above 70000)
- Document your port usage: Keep track of which services use which ports
- Check the limit: Remember the 64 port limit per instance
- Use environment variables: Leverage predefined port variables in your scripts