48 lines
1.3 KiB
Markdown
48 lines
1.3 KiB
Markdown
# docker-sshtunnel
|
|
|
|
[![Build Status](https://drone.asperti.com/api/badges/paspo/docker-sshtunnel/status.svg)](https://drone.asperti.com/paspo/docker-sshtunnel)
|
|
|
|
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
|
|
|
|
```bash
|
|
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
|
|
|
|
```yaml
|
|
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
|
|
```
|