Sign inSign up

manydesigns/docker-ssh-tunnel

By manydesigns

•Updated over 5 years ago

Expose SSH tunnel over a server

Image
0

526

manydesigns/docker-ssh-tunnel repository overview

⁠Docker SSH Tunnel

This Docker creates a simple SSH tunnel over a server. It is very useful when your container needs to access to an external protected resource. In this case this container might behave like a proxy to outer space inside your Docker network.

⁠Usage

  1. First you should create a config file in your local directory. For simplicity you can create this file in ~/.ssh in your local machine.

  2. Inside ~/.ssh/config put these lines:

    Host mysql-tunnel # You can use any name
            HostName ssh-tunnel.corporate.tld # Tunnel 
            IdentityFile ~/.ssh/id_rsa # Private key location
            User cagatay.guertuerk # Username to connect to SSH service
            ForwardAgent yes
            TCPKeepAlive yes
            ConnectTimeout 5
            ServerAliveCountMax 10
            ServerAliveInterval 15
  1. Don't forget to put your private key (id_rsa) to ~/.ssh folder.

  2. Now in docker-compose.yml you can define the tunnel as follows:

    version: '2'
    services:
      mysql:
        image: manydesigns/docker-ssh-tunnel:1.0
        volumes:
          - $HOME/.ssh:/ssh:ro
        environment:
          TUNNEL_HOST: mysql-tunnel
          CONNECTIONS: '3306:tunneled-sql.corporate.internal.tld:3306'
  1. Run docker-compose up -d

After you start up docker containers, any container in the same network will be able to access to tunneled mysql instance using tcp://mysql:3306. Of course you can also expose port 3306 to be able to access to tunneled resource from your host machine.

⁠Multiple connections
    version: '2'
    services:
      tunnels:
        image: manydesigns/docker-ssh-tunnel:1.0
        volumes:
          - $HOME/.ssh:/ssh:ro
        ports:
          - 5432:5432
          - 3306:3306
        environment:
          TUNNEL_HOST: myhost.internal.com
          CONNECTIONS: '3306:mysql.internal.com:3306 5432:postgresql.internal.com:5432'

You can just specify multiple connection separated by space, and of course you can expose multiple ports to the host

Tag summary

Content type

Image

Digest

Size

4.4 MB

Last updated

over 5 years ago

docker pull manydesigns/docker-ssh-tunnel