mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
fix(docker/container): handle multiple ips with the same port (#4121)
* fix(containers): handle multiple ips with the same port * fix(containers): fix parsing
This commit is contained in:
parent
cb1a1e7be5
commit
c5731e237e
2 changed files with 25 additions and 14 deletions
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue