Giter VIP home page Giter VIP logo

docker-ssh-tunnel's Introduction

ssh-tunnel

This is a lightweight Docker image that creates a simple SSH tunnel using autossh on a server. It is useful when you need to connect to an external, protected server.

Usage

First, you need to write the ssh configuration in the local directory ~/.ssh/config. An example of the configuration is shown below.

Host tunnel-server # You can use any name you like
  HostName ssh-tunnel.test # Host name of the tunnel server
  User username # The user name to use for the ssh connection
  IdentityFile ~/.ssh/id_rsa # Private key location

The following is an example of docker-compose.yml for tunneling to multiple database servers.

version: '3'

networks:
  network_link:
    external: true

services:
  mysql-tunnel:
    image: karibash/ssh-tunnel
    container_name: mysql-tunnel
    ports:
      - 3306:3306
    networks:
      - network_link
    volumes:
      - ${HOME}/.ssh:/root/.ssh
      - type: bind
        source: /run/host-services/ssh-auth.sock
        target: /run/host-services/ssh-auth.sock
    environment:
      - SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock
      - TUNNEL_ENV_PREFIX=MY_SQL
      - MY_SQL_TUNNEL_EXPOSE_PORT=3306
      - MY_SQL_TUNNEL_DESTINATION_HOST=mysql-server.test
      - MY_SQL_TUNNEL_DESTINATION_PORT=3306
      - MY_SQL_TUNNEL_SERVER_HOST_NAME=tunnel-server

  postgres-tunnel:
    image: karibash/ssh-tunnel
    container_name: postgres-tunnel
    ports:
      - 5432:5432
    networks:
      - network_link
    volumes:
      - ${HOME}/.ssh:/root/.ssh
      - type: bind
        source: /run/host-services/ssh-auth.sock
        target: /run/host-services/ssh-auth.sock
    environment:
      - SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock
      - TUNNEL_ENV_PREFIX=POSTGRES
      - POSTGRES_TUNNEL_EXPOSE_PORT=5432
      - POSTGRES_TUNNEL_DESTINATION_HOST=postgres-server.test
      - POSTGRES_TUNNEL_DESTINATION_PORT=5432
      - POSTGRES_TUNNEL_SERVER_HOST_NAME=tunnel-server

Finally, you can start the server by using the docker-compose up -d command.

docker-ssh-tunnel's People

Contributors

karibash avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.