docker exec -it <containterid> ssh -R5432:localhost:5432 <user>@<hostip>
By default, OpenSSH only allows connecting to remote forwarded ports from the server host. However, the GatewayPorts option in the server configuration file sshd_config can be used to control this. The following alternatives are possible:
GatewayPorts no
This prevents connecting to forwarded ports from outside the server computer.
GatewayPorts yes
This allows anyone to connect to the forwarded ports. If the server is on the public Internet, anyone on the Internet can connect to the port.
GatewayPorts clientspecified
This means that the client can specify an IP address from which connections to the port are allowed. The syntax for this is:
ssh -R 52.194.1.73:8080:localhost:80 host147.aws.example.com
In this example, only connections from the IP address 52.194.1.73 to port 8080 are allowed.