Skip to content

Commit

Permalink
added opts for manually choosing container network, port and path
Browse files Browse the repository at this point in the history
  • Loading branch information
paulll committed Mar 29, 2020
1 parent d9a321a commit 43a52cb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
};
Expand All @@ -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);
});
Expand Down

0 comments on commit 43a52cb

Please sign in to comment.