Skip to main content

Give a service a fixed port in every slot

A Port variable gets a free port for each slot, picked by the node when a task takes the slot. By default the number can change from one task to the next. Give the variable a preferred port and the service gets that number whenever it can, so you can bookmark it, put it in a test config or open it through a tunnel.

The node uses the preferred port when it is free on that host and no other slot has it. Otherwise it gives the next free port. Two slots never share a port, so a second slot of the same project on one node gets a different number.

Who can do this: anyone who can edit the project. A Port variable always applies to everyone; it can't be an Only me override.

Set a preferred port​

  1. In the sidebar, select Directory, then the Projects tab.
  2. Select the project's name to open its settings, then select Variables in its list of sections.
  3. Select Add variable, or select the name of an existing Port variable to change it.
  4. Enter the Variable name your stack reads its port from, such as WEB_PORT.
  5. In Value from, pick Port.
  6. In Port, pick Preferred port, then type the port, such as 5173. It must be from 1024 to 65535.
  7. Select Create, or Save on an existing variable.

To go back to any free port, pick Auto-assigned per slot in Port and select Save.

A new or changed port reaches each slot the next time a task takes it. A stack already running in a slot keeps its old port until then.