Tunnel all docker ports on remote server to localhost
tunnel all ports of running container on a remote server to localhost
tunnel.sh content
#!/bin/bashSSH_SERVER=$1;if [ -z $1 ] ; thenecho"Usage: ./tunnel <ssh-server-name>"&&exit1;fiPORTS=$(ssh $SSH_SERVER dockerps--format"{{.Ports}}"|grep:|awk-F-'{print $1}'|awk-F:'{print $2}')for PORT in $PORTSdoecho"tunneling port $PORT..."ssh-N-L $PORT:127.0.0.1:$PORT $SSH_SERVER &doneread-rsn1-p"Press any key to exit";kill $(jobs-p);psS|grep"ssh -N -L "|awk'{print $1}'|xargskill-9
usage
chmod +x tunnel.sh
# Tunnel all port of containers run on remote server
./tunnel.sh ssh_remote_server
# Tunnel all port of containers & another port
./tunnel.sh ssh_remote_server 808