Forward port

2 snippets across 2 stacks — Bash & Linux, Docker

Also written as port forward

SHBash & Linux

Secure Shell Remote Login

SH · Networking
syntax
ssh [options] user@host
example
ssh deploy@10.0.1.50
ssh -i ~/.ssh/prod_key.pem ec2-user@server.example.com
ssh -L 5432:db-host:5432 bastion@jump.example.com

Note -i specifies a private key file. -L sets up local port forwarding (the example tunnels a remote Postgres port to localhost:5432). -p sets a non-standard SSH port. Add -v for verbose debugging of connection issues.

DKDocker

Port Mapping (-p)

DK · Run Options
syntax
docker run -p <host_port>:<container_port> <image>
docker run -p <host_ip>:<host_port>:<container_port> <image>
example
docker run -d -p 8080:3000 myapp:1.0
docker run -d -p 127.0.0.1:5432:5432 postgres:16

Note The format is always host:container. Binding to 127.0.0.1 restricts access to localhost only — critical for databases you do not want exposed on the network. Without an IP, Docker binds to 0.0.0.0 (all interfaces).