SSH tunneling to remote server with docker

I am trying to write a Dockerfile to access a remote mySQL database using ssh tunneling.

Tried with the following Run command:

  • Running script outside of docker container
  • Docker trusted build doesn't show up in search
  • How to retrieve only containers running a specific image in go-dockerclient?
  • docker info: are huge (tens-of-thousands) container counts normal?
  • Docker container not accessible in host machine
  • Meaning and usage of <alias>_PORT_<port>_<proto>_* env vars in linked containers
  • ssh   -f -N username@hostname -L [local port]:[database host]:[remote port] StrictHostKeyChecking=no

    and getting this error:

    “Host key verification failed” ERROR

  • Pycharm 2016.1.4 (newest) and Docker issue
  • docker nginx container not receiving request from outside, connection refused
  • Deploy a Dockerized Symfony2 application on AWS Elastic Beanstalk
  • AWS Elastic Beanstalk Docker PHP application
  • Will docker-compose allow mapping a port to two ports or do I need an ambassador?
  • Error on Docker Pull - “Layer already being pulled by another client”
  • One Solution collect form web for “SSH tunneling to remote server with docker”

    Assuming that the Docker container does not have access to any SSH data (i.e.: there is no ~/.ssh/known_hosts), you have two ways to handle this:

    1. Use ssh-keyscan -t rsa > ~/.ssh/my_known_hosts from within the container to add the remote host
    2. Or copy the relevant line from an existing my_known_hosts or simply COPY a the whole file to the container.

    Either of these approaches should do it.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.