Skip to content

Instantly share code, notes, and snippets.

@iximiuz
Created January 17, 2026 16:18
Show Gist options
  • Select an option

  • Save iximiuz/255aca2888c8a13a556dd2172175d0c0 to your computer and use it in GitHub Desktop.

Select an option

Save iximiuz/255aca2888c8a13a556dd2172175d0c0 to your computer and use it in GitHub Desktop.

Start a new playground with a service (e.g., Nginx) in it:

$ labctl p start --ssh docker
> docker run -d --restart always -p 8080:80 nginx:alpine
> exit

Forward local port to make the remote service accessible on the local machine:

$ labctl port-forward <PLAY_ID> -L 9999:8080
$ curl localhost:9999
<html>
Welcome to nginx...

Stop the playground when done (persisting the state):

$ labctl p stop <PLAY_ID>
Stopping playground 696951d4a1d5affa6b3cf208...
Waiting for playground to stop... Done.

Next day, restart the playground AND forward local ports automatically using the new --with-port-forwards flag:

$ labctl p restart --with-port-forwards <PLAY_ID>
Restarting playground 696951d4a1d5affa6b3cf208...
Waiting for playground to restart... Done.
Playground has been restarted.
Restoring 1 port forward(s)...
SSH-ing into docker-01 machine...
Forwarding 127.0.0.1:9999 -> :8080 (machine: docker-01)

Now you can access Nginx from the playground on the local port 9999. No need to manually forward all the previously forwarded ports again.

Bonus: Some handy helper commands:

  1. List playground's "should be forwarded ports":
$ labctl port-forward --list <PLAY_ID>
Saved port forwards:
  [0] docker-01 (local): 127.0.0.1:9999 -> 8080
  1. Restore forwarded ports for a running playground (if labctl p restart was used w/o --with-port-forwards):
$ labctl port-forward --restore <PLAY_ID>
Restoring 1 port forward(s)...
Forwarding 127.0.0.1:9999 -> :8080 (machine: docker-01)
  1. "Unforward" a previously forwarded port (by its index in the list):
$ labctl port-forward --remove 0
  1. Start a new playground from a template that has preconfigured port forwards:
$ labctl p start --with-port-forwards <my-custom-playground>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment