Forward ssh connections to docker container by hostname

Solution 1:

Doing this "by hostname" is simply not inside the scope of ssh. The ssh protocol itself does not support name-based virtual hosting (in fact HTTP is the exception from the rule here).

The SSHd on the receiving side can never know what hostname you asked your client to connect to as this information is not passed inside the protocol.

If you just need a few clients to work with this you can configure each client to connect to your server and then jump to the docker container like follows:

Host yourcontainer
        Hostname internal.ip.of.your.container
        ProxyCommand ssh your.docker.host nc %h %p

This way ssh will invoke the proxy command which will open an ssh session to your host and call netcat to establish a connection to your container. This way you don't really need to expose your containers ssh port to the outside world.