https://github.com/karibash/docker-ssh-tunnel
This is a lightweight Docker image that creates a simple SSH tunnel using autossh on a server.
https://github.com/karibash/docker-ssh-tunnel
docker docker-compose ssh tunnel
Last synced: 2 months ago
JSON representation
This is a lightweight Docker image that creates a simple SSH tunnel using autossh on a server.
- Host: GitHub
- URL: https://github.com/karibash/docker-ssh-tunnel
- Owner: Karibash
- License: mit
- Created: 2021-11-09T11:13:02.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-12T10:24:28.000Z (over 4 years ago)
- Last Synced: 2025-11-29T17:26:28.716Z (7 months ago)
- Topics: docker, docker-compose, ssh, tunnel
- Language: Shell
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.