Use DOCKER_HOST from env if possible, and no connection options are available

Connects-to: #625
Change-Type: patch
This commit is contained in:
Tim Perry 2017-08-23 14:14:46 +02:00
parent e8c4a9abfd
commit 2bbd45e867
3 changed files with 10 additions and 2 deletions

View File

@ -68,8 +68,9 @@ exports.appendOptions = function(opts) {
};
exports.generateConnectOpts = generateConnectOpts = function(opts) {
var Promise, _, fs;
var Promise, _, buildDockerodeOpts, fs;
Promise = require('bluebird');
buildDockerodeOpts = require('dockerode-options');
fs = require('mz/fs');
_ = require('lodash');
return Promise["try"](function() {
@ -82,6 +83,8 @@ exports.generateConnectOpts = generateConnectOpts = function(opts) {
connectOpts.port = opts.dockerPort || 2376;
} else if ((opts.docker != null) && (opts.dockerHost != null)) {
throw new Error("Both a local docker socket and docker host have been provided. Don't know how to continue.");
} else if (process.env.DOCKER_HOST) {
connectOpts = buildDockerodeOpts(process.env.DOCKER_HOST);
} else {
connectOpts.socketPath = '/var/run/docker.sock';
}

View File

@ -86,6 +86,7 @@ exports.appendOptions = (opts) ->
exports.generateConnectOpts = generateConnectOpts = (opts) ->
Promise = require('bluebird')
buildDockerodeOpts = require('dockerode-options')
fs = require('mz/fs')
_ = require('lodash')
@ -103,8 +104,11 @@ exports.generateConnectOpts = generateConnectOpts = (opts) ->
else if opts.docker? and opts.dockerHost?
# Both provided, no obvious way to continue
throw new Error("Both a local docker socket and docker host have been provided. Don't know how to continue.")
else if process.env.DOCKER_HOST
# If no explicit options are provided, use the env
connectOpts = buildDockerodeOpts(process.env.DOCKER_HOST)
else
# None provided, assume default docker local socket
# No options anywhere, assume default docker local socket
connectOpts.socketPath = '/var/run/docker.sock'
# Now need to check if the user wants to connect over TLS

View File

@ -51,6 +51,7 @@
"docker-qemu-transpose": "^0.2.2",
"docker-toolbelt": "^1.3.3",
"dockerode": "^2.5.0",
"dockerode-options": "^0.2.1",
"drivelist": "^5.0.22",
"etcher-image-write": "^9.0.3",
"global-tunnel-ng": "github:zvin/global-tunnel#dont-proxy-connections-to-file-sockets",