apocas / docker-modem

Docker Remote API network stack driver.
Apache License 2.0
234 stars 112 forks source link

connect to docker through ssh connection #80

Closed jinxidoru closed 7 years ago

jinxidoru commented 7 years ago

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 7 years ago

@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

jinxidoru commented 7 years ago

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

rmg commented 7 years ago

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

});
jinxidoru commented 7 years ago

This won't attach to the unix domain socket though, correct? It would require that the remote host be exposing the docker API on a tcp port, correct?

On Jun 10, 2017, at 12:37 PM, Ryan Graham notifications@github.com wrote:

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

}); — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

rmg commented 7 years ago

Yes, it was written for TCP connections.