Skip to content

Commit 43a52cb

Browse files
committed
added opts for manually choosing container network, port and path
1 parent d9a321a commit 43a52cb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/docker.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ DockerModule.prototype.register = function (src, target, opts) {
131131

132132
DockerModule.prototype.registerContainer = function (src, containerId, opts) {
133133
var _this = this;
134-
containerPort(this.dolphin, containerId).then(function (targetPort) {
135-
_this.redbird.register(src, targetPort, opts);
134+
containerPort(this.dolphin, containerId, opts).then(function (targetPort) {
135+
_this.redbird.register(src, targetPort + (opts.container && opts.container.path ? '/' + opts.container.path : ''), opts);
136136
_this.ports[containerId] = targetPort;
137137
});
138138
};
@@ -142,18 +142,26 @@ function isMatchingImageName(targetName, imageName) {
142142
return regex.test(imageName);
143143
}
144144

145-
function containerPort(dolphin, containerId) {
145+
function containerPort(dolphin, containerId, opts) {
146146
return dolphin.containers.inspect(containerId).then(function (container) {
147147
var port = Object.keys(container.NetworkSettings.Ports)[0].split('/')[0];
148+
if (opts.container && opts.container.port && container.NetworkSettings.Ports.hasOwnProperty([opts.container.port + '/tcp'])) {
149+
port = opts.container.port;
150+
}
148151

149-
var netNames = Object.keys(container.NetworkSettings.Networks);
152+
var ip, netNames = Object.keys(container.NetworkSettings.Networks);
150153
if (netNames.length === 1) {
151-
var ip = container.NetworkSettings.Networks[netNames[0]].IPAddress;
154+
ip = container.NetworkSettings.Networks[netNames[0]].IPAddress;
152155
if (port && ip) {
153156
return 'http://' + ip + ':' + port;
154157
}
155158
} else {
156-
//TODO: Implements opts for manually choosing the network/ip/port...
159+
if (opts.container && opts.container.network && container.NetworkSettings.Networks[opts.container.network]) {
160+
ip = container.NetworkSettings.Networks[opts.container.network].IPAddress;
161+
if (port && ip) {
162+
return 'http://' + ip + ':' + port;
163+
}
164+
}
157165
}
158166
throw Error('No valid address or port ' + container.IPAddress + ':' + port);
159167
});

0 commit comments

Comments
 (0)