apocas/docker-modem

connect to docker through ssh connection

jinxidoru opened this issue · 5 comments

First off, thanks for creating docker-modem and dockerode. They have been very helpful recently.

I have a use-case where I would like to connect to a docker container on a server which is accessible through ssh. I am doing some slightly unholy acts to make this work locally, but I'm pretty sure there's an easy solution that could be implemented by giving docker-modem the ability to tunnel to a docker socket through an ssh connection. I'd be happy to add this functionality if it were something that you would be open to accepting in a pull request. I wanted to reach out first before to make sure their was interest before taking the time to do it.

Let me know what you think.

rmg commented

@jinxidoru you might want to take a look at strong-tunnel.

I haven't tested it with docker specifically, but it was originally built to work with an http protocol similar to docker's (eg. mix of requests websockets), so it should be able to handle things like connection hijacking like Docker does for streams.

disclaimer: I wrote it

Oh nice. Have you considered creating an integration with docker-modem?

rmg commented

This should be all the integration you need:

var st = require('strong-tunnel');
var Docker = require('dockerode');

// the '+ssh' tells strong-tunnel to make an ssh tunnel and proxy
var remoteDocker = 'tcp+ssh://192.168.1.100:5000';

st(remoteDocker, function(err, url) {
  // this returned url the local proxy, something like 'tcp://127.0.0.1:23989'

  // docker requests now tunnelled over ssh via a local proxy
  process.env.DOCKER_HOST = url;
  var docker = new Docker();

  // your normal docker.* calls here

});
rmg commented

Yes, it was written for TCP connections.