fix(docker/container): handle multiple ips with the same port (#4121)
* fix(containers): handle multiple ips with the same port * fix(containers): fix parsingpull/4184/head
parent
cb1a1e7be5
commit
c5731e237e
|
@ -179,7 +179,11 @@ angular.module('portainer.docker').factory('ContainerHelper', [
|
|||
}
|
||||
|
||||
const bindKey = containerPort + '/' + portBinding.protocol;
|
||||
bindings[bindKey] = [{ HostIp: hostIp, HostPort: hostPort }];
|
||||
if (bindings[bindKey]) {
|
||||
bindings[bindKey].push({ HostIp: hostIp, HostPort: hostPort });
|
||||
} else {
|
||||
bindings[bindKey] = [{ HostIp: hostIp, HostPort: hostPort }];
|
||||
}
|
||||
}
|
||||
});
|
||||
return bindings;
|
||||
|
@ -196,12 +200,15 @@ angular.module('portainer.docker').factory('ContainerHelper', [
|
|||
|
||||
_.forEach(portBindingKeysByProtocol, (portBindingKeys, protocol) => {
|
||||
// Group the port bindings by host IP
|
||||
const portBindingKeysByHostIp = _.groupBy(portBindingKeys, (portKey) => {
|
||||
const portBinding = portBindings[portKey][0];
|
||||
return portBinding.HostIp || '';
|
||||
});
|
||||
const portBindingKeysByHostIp = {};
|
||||
for (const portKey of portBindingKeys) {
|
||||
for (const portBinding of portBindings[portKey]) {
|
||||
portBindingKeysByHostIp[portBinding.HostIp] = portBindingKeysByHostIp[portBinding.HostIp] || [];
|
||||
portBindingKeysByHostIp[portBinding.HostIp].push(portKey);
|
||||
}
|
||||
}
|
||||
|
||||
_.forEach(portBindingKeysByHostIp, (portBindingKeys) => {
|
||||
_.forEach(portBindingKeysByHostIp, (portBindingKeys, ip) => {
|
||||
// Sort by host port
|
||||
const sortedPortBindingKeys = _.orderBy(portBindingKeys, (portKey) => {
|
||||
return parseInt(_.split(portKey, '/')[0]);
|
||||
|
@ -213,6 +220,7 @@ angular.module('portainer.docker').factory('ContainerHelper', [
|
|||
const portKeySplit = _.split(portKey, '/');
|
||||
const containerPort = parseInt(portKeySplit[0]);
|
||||
const portBinding = portBindings[portKey][0];
|
||||
portBindings[portKey].shift();
|
||||
const hostPort = parsePort(portBinding.HostPort);
|
||||
|
||||
// We only combine single ports, and skip the host port ranges on one container port
|
||||
|
@ -234,8 +242,8 @@ angular.module('portainer.docker').factory('ContainerHelper', [
|
|||
}
|
||||
|
||||
let bindingHostPort = portBinding.HostPort.toString();
|
||||
if (portBinding.HostIp) {
|
||||
bindingHostPort = portBinding.HostIp + ':' + bindingHostPort;
|
||||
if (ip) {
|
||||
bindingHostPort = `${ip}:${bindingHostPort}`;
|
||||
}
|
||||
|
||||
const binding = {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import moment from 'moment';
|
||||
import _ from 'lodash-es';
|
||||
import { PorImageRegistryModel } from 'Docker/models/porImageRegistry';
|
||||
|
||||
angular.module('portainer.docker').controller('ContainerController', [
|
||||
|
@ -83,12 +84,14 @@ angular.module('portainer.docker').controller('ContainerController', [
|
|||
|
||||
$scope.portBindings = [];
|
||||
if (container.NetworkSettings.Ports) {
|
||||
angular.forEach(Object.keys(container.NetworkSettings.Ports), function (portMapping) {
|
||||
if (container.NetworkSettings.Ports[portMapping]) {
|
||||
var mapping = {};
|
||||
mapping.container = portMapping;
|
||||
mapping.host = container.NetworkSettings.Ports[portMapping][0].HostIp + ':' + container.NetworkSettings.Ports[portMapping][0].HostPort;
|
||||
$scope.portBindings.push(mapping);
|
||||
_.forEach(Object.keys(container.NetworkSettings.Ports), function (key) {
|
||||
if (container.NetworkSettings.Ports[key]) {
|
||||
_.forEach(container.NetworkSettings.Ports[key], (portMapping) => {
|
||||
const mapping = {};
|
||||
mapping.container = key;
|
||||
mapping.host = `${portMapping.HostIp}:${portMapping.HostPort}`;
|
||||
$scope.portBindings.push(mapping);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue