|
| 1 | + |
| 2 | +# Docker SSH tunnel |
| 3 | + |
| 4 | +This docker image can be used in case when you need |
| 5 | +an access, for example, to some service on your production server, |
| 6 | +which doesn't expose it's ports to the worldwide. |
| 7 | +Additionally, you don't want to touch ports on your local machine, |
| 8 | +because some of them can be busy or just reserved. |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +### docker run |
| 13 | + |
| 14 | +### docker-compose.yml |
| 15 | + |
| 16 | +The minimal configuration will look like: |
| 17 | + |
| 18 | +``` |
| 19 | +services: |
| 20 | + ssh-tunnel-example: |
| 21 | + image: symfonydoge/docker-ssh-tunnel:latest |
| 22 | + volumes: |
| 23 | + - $HOME/.ssh/id_rsa:/root/ssh-import/id_rsa:ro |
| 24 | + environment: |
| 25 | + SSH_TUNNEL_HOST: corp.domain.ltd |
| 26 | + REMOTE_PORT: 6379 |
| 27 | +``` |
| 28 | + |
| 29 | +where `$HOME/.ssh/id_rsa` is a path to your private SSH key, |
| 30 | +`corp.domain.ltd` is a domain or IP address of your server |
| 31 | +and `6379` is the remote port to forward |
| 32 | +(local port will be the same if not specified explicitly, |
| 33 | +see full list of environment variables below). |
| 34 | + |
| 35 | +Now each container in the compose project can access |
| 36 | +tunnelled resource through `ssh-tunnel-example:6379`. |
| 37 | + |
| 38 | +### Environment Variables |
| 39 | + |
| 40 | +| Name | Default value | Description | |
| 41 | +| :---------------- | :------------ | :-------------------------------------------------------------------------------- | |
| 42 | +| `LOCAL_HOST` | * | IP address or domain to present remote resource in the tunnel container | |
| 43 | +| `LOCAL_PORT` | equal to `REMOTE_PORT` | Port number to present remote resource in the tunnel container | |
| 44 | +| `REMOTE_HOST` | 127.0.0.1 | IP address or domain of resource on the remote server by which it can be accessed | |
| 45 | +| `REMOTE_PORT` | | Port number of resource on the remote server by which it can be accessed | |
| 46 | +| `SSH_TUNNEL_HOST` | | Host of the remote server to create an SSH tunnel | |
| 47 | +| `SSH_TUNNEL_PORT` | 22 | SSH daemon port on the remote server | |
| 48 | +| `SSH_TUNNEL_USER` | root | User login for establishing an SSH connection | |
| 49 | + |
| 50 | +### Hints |
| 51 | + |
| 52 | +- You can expose a port only for local access |
| 53 | +in your docker-compose project, just specify localhost |
| 54 | +in the mapping: `127.0.0.1:6379:6379`. See [documentation](https://docs.docker.com/config/containers/container-networking/). |
| 55 | + |
| 56 | +## Changelog |
| 57 | +All notable changes to this project will be documented in [CHANGELOG.md](CHANGELOG.md). |
0 commit comments