diff --git a/lib/docker.js b/lib/docker.js index 69a12ad..86960b8 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -131,8 +131,8 @@ DockerModule.prototype.register = function (src, target, opts) { DockerModule.prototype.registerContainer = function (src, containerId, opts) { var _this = this; - containerPort(this.dolphin, containerId).then(function (targetPort) { - _this.redbird.register(src, targetPort, opts); + containerPort(this.dolphin, containerId, opts).then(function (targetPort) { + _this.redbird.register(src, targetPort + (opts.container && opts.container.path ? '/' + opts.container.path : ''), opts); _this.ports[containerId] = targetPort; }); }; @@ -142,18 +142,26 @@ function isMatchingImageName(targetName, imageName) { return regex.test(imageName); } -function containerPort(dolphin, containerId) { +function containerPort(dolphin, containerId, opts) { return dolphin.containers.inspect(containerId).then(function (container) { var port = Object.keys(container.NetworkSettings.Ports)[0].split('/')[0]; + if (opts.container && opts.container.port && container.NetworkSettings.Ports.hasOwnProperty([opts.container.port + '/tcp'])) { + port = opts.container.port; + } - var netNames = Object.keys(container.NetworkSettings.Networks); + var ip, netNames = Object.keys(container.NetworkSettings.Networks); if (netNames.length === 1) { - var ip = container.NetworkSettings.Networks[netNames[0]].IPAddress; + ip = container.NetworkSettings.Networks[netNames[0]].IPAddress; if (port && ip) { return 'http://' + ip + ':' + port; } } else { - //TODO: Implements opts for manually choosing the network/ip/port... + if (opts.container && opts.container.network && container.NetworkSettings.Networks[opts.container.network]) { + ip = container.NetworkSettings.Networks[opts.container.network].IPAddress; + if (port && ip) { + return 'http://' + ip + ':' + port; + } + } } throw Error('No valid address or port ' + container.IPAddress + ':' + port); });