You can use this docker container to create a SSH tunnel to a remote machine and have it "visible" inside your docker environment.
Go to file
Paolo Asperti d7fafd0928
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
initial release
2021-03-19 09:35:59 +01:00
.drone.yml initial release 2021-03-19 09:35:59 +01:00
Dockerfile initial release 2021-03-19 09:35:59 +01:00
entrypoint.sh initial release 2021-03-19 09:35:59 +01:00
LICENSE Initial commit 2021-03-19 08:16:55 +00:00
README.md initial release 2021-03-19 09:35:59 +01:00

docker-sshtunnel

Build Status

You can use this docker container to create a SSH tunnel to a remote machine and have it "visible" inside your docker environment.

Usage example

With the following settings, you have a container that establishes an SSH session with the specified remote machine, forwards remote mysql port to a port on the local container itself which is then exported by the local docker.

That way you can connect to a remote mysql server (even if not directly exposed) as if it is running on your machine.

Plain docker

docker run --rm -ti \
    -e SSH_USER=root \
    -e SSH_HOST=myremoteserver.mydomain.com \
    -e REMOTE_PORT=3306 \
    -e LOCAL_PORT=3306 \
    -e REMOTE_HOST=127.0.0.1 \
    -p 3306:3306 \
    -v /home/me/.ssh/id_rsa:/id_rsa \
    --name stu \
    docker.asperti.com/paspo/sshtunnel:latest

docker-compose

version: "3"
services:

  backup-slave:
    image: docker.asperti.com/paspo/sshtunnel:latest
    restart: unless-stopped
    volumes:
      - "/home/me/.ssh/id_rsa:/id_rsa"
    environment:
      - SSH_USER=root
      - SSH_HOST=myremoteserver.mydomain.com
      - REMOTE_PORT=3306
      - LOCAL_PORT=3306
      - REMOTE_HOST=127.0.0.1
    ports:
      - 3306:3306