Skip to content
Run Remote Docker commands via a SSH Tunnel
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Run Remote Docker commands via a SSH Tunnel

Docker Remote Tunnel

Run Remote Docker commands via a SSH Tunnel. Docker Hub: ruanbekker/docker-remote-tunnel


I made this wrapper to simplify ci/cd deployments with concourse to deploy applications to docker swarm.

The wrapper creates a screen session, creates a ssh tunnel and mounting a local port to the docker socket on the manager node, allowing us to run docker commands locally, interfacing with the remote docker api.


Run a container, and map the path to your ssh key

$ docker run -v ~/.ssh/id_rsa:/tmp/key -it ruanbekker/docker-remote-tunnel sh

Wrapper supports creating and terminating the tunnels:

$ docker-tunnel --help

Usage: /usr/bin/docker-tunnel
Description: Execute remote docker commands via ssh tunnel over a docker socket

 -h, --help                    Display usage instructions
 -c, --connect []  Establishes Tunnel to Remote SSH Server. Expects username@remote-server
 -t, --terminate               Terminates Tunnel

Establish a SSH Tunnel to your Manager node:

$ docker-tunnel -c

  Source the environment either with:

  1) source /root/
  2) export DOCKER_HOST="localhost:2376"

Source the environment:

$ source /root/

Validate that the DOCKER_HOST variable has been set:

$ env | grep DOCKER

Run a docker command from the container:

$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
9kbmvcr73ceh2afozxrwx3CzT *   swarm-manager-1     Ready               Active              Leader              18.06.3-ce
vuxEvsv09qvRekwcltk7prmkx     swarm-worker-1      Ready               Active                                  18.06.3-ce

Terminate the tunnel:

$ docker-tunnel --terminate

Verify that the tunnel has been terminated:

$ docker node ls
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Docker Hub Image

You can’t perform that action at this time.