Skip to content

Instantly share code, notes, and snippets.

@slowprog
Created July 3, 2018 22:33
Show Gist options
  • Save slowprog/0a6827170a19a413ce688b6582e5224c to your computer and use it in GitHub Desktop.
Save slowprog/0a6827170a19a413ce688b6582e5224c to your computer and use it in GitHub Desktop.
How to SSH tunnel to a Docker container on a remote server
For example temporary connect to Postgres.
1. Expose the port within your Docker container to the remote server
```
# docker.example.com.yaml
version: '3.3'
services:
postgres:
image: postgres:9.6-alpine
ports:
- "6543:5432"
```
2. Deploy.
3. On your machine, make a tunnel:
```
ssh -NL 3001:localhost:6543 root@$(docker-machine ip docker.example.com)
```
4. Use psql from your machine.
5. Remove from docker.example.com.yaml "6543:5432" after work cause it's public! And deploy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment