Open a service

Reach a container's port from your machine without putting it on the internet.

A port your containers publish is open on the host only. Nobody on the internet can reach it, and neither can you, until you forward it to your own machine over SSH. Then it answers at localhost as if the service ran on your laptop.

Open a port

Keep this running in a terminal, then visit http://localhost:3000:

your terminal
ssh -N -L 3000:localhost:3000 -p 2222 my-laptop@ssh.raftrun.com

Use your host's name in place of my-laptop. The Stats window on the Docker hosts page lists each container's published ports; click one to copy this command for that port. It works the same on macOS, Linux and Windows.

Several ports

Add one -L for each:

your terminal
ssh -N -p 2222 my-laptop@ssh.raftrun.com \
  -L 3000:localhost:3000 \
  -L 5432:localhost:5432 \
  -L 8080:localhost:8080

The first number is the port on your machine and the last is the host's. If 5432 is taken on your laptop, -L 15432:localhost:5432 opens the host's database at localhost:15432 instead.

Keep the forwards in your SSH config

~/.ssh/config
Host my-laptop-ports
  HostName ssh.raftrun.com
  Port 2222
  User my-laptop
  LocalForward 3000 localhost:3000
  LocalForward 5432 localhost:5432

Then ssh -N my-laptop-ports opens them all.

Why not a public address

A dev stack usually runs with default passwords, debug pages and seeded data. Putting it on a public URL would hand all of that to anyone who finds the address, so the host's firewall keeps published ports off the internet, and the only way in is through SSH with your key. To show your work to someone, invite them to the workspace or deploy it to a real environment.

Things to know

  • A host with a port forward open counts as in use: it doesn't stop for being idle. It stops 10 minutes after you close the last forward.
  • If the host was stopped, the forward starts it. The first request waits 15 to 30 seconds.
  • Only TCP can be forwarded. UDP ports show in the dashboard but can't be opened this way.