SSH Tunneling to docker container SSH Tunneling to docker container docker docker

SSH Tunneling to docker container


You might want to reconsider using SSH. As the comments in your linked post point out, this goes against Docker's concept. Furthermore, running addtional SSH server(s) increases your potential attack surface.

There are two alternatives for getting access to your containers:

  1. SSH into your VM and use docker exec, e.g. docker exec -it <yourcontainer> bash
  2. Connect your local client to the docker daemon running inside your VM. This is an advanced approach, but Docker has a good documentation how to do it securely. In a nuthshell: You configure the daemon on your VM to listen to a TCP socket, e.g. dockerd -H=0.0.0.0:2376. Then you point your local client to the corresponding IP, docker -H=$HOST:2376 version. Everyting must be secured by using signed TLS certificates.

I hope this helps!


You can bypass that issue by adding this to your ssh command:

-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no

To solve the authentication problem, follow this guide to create an authorized_keys file and finally add it to your image using the Dockerfile:

ADD authorized_keys /home/docker/.ssh/authorized_keys

NOTE: as @stepf comments ssh is not intended way to access docker containers.