From ffca4401357e015d4352a3a63087dd53c66334fb Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Thu, 30 Mar 2017 12:00:16 +0200 Subject: [PATCH] fix(services): let Docker automatically assign port when PublishedPort is not defined (#747) --- .../createService/createServiceController.js | 11 +++++++++-- app/components/service/serviceController.js | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/components/createService/createServiceController.js b/app/components/createService/createServiceController.js index 93d5b047c..f7b1d100a 100644 --- a/app/components/createService/createServiceController.js +++ b/app/components/createService/createServiceController.js @@ -83,8 +83,15 @@ function ($scope, $state, Service, Volume, Network, ImageHelper, Authentication, function preparePortsConfig(config, input) { var ports = []; input.Ports.forEach(function (binding) { - if (binding.PublishedPort && binding.TargetPort) { - ports.push({ PublishedPort: +binding.PublishedPort, TargetPort: +binding.TargetPort, Protocol: binding.Protocol }); + var port = { + Protocol: binding.Protocol + }; + if (binding.TargetPort) { + port.TargetPort = +binding.TargetPort; + if (binding.PublishedPort) { + port.PublishedPort = +binding.PublishedPort; + } + ports.push(port); } }); config.EndpointSpec.Ports = ports; diff --git a/app/components/service/serviceController.js b/app/components/service/serviceController.js index fa2cea01d..fff240cc1 100644 --- a/app/components/service/serviceController.js +++ b/app/components/service/serviceController.js @@ -197,6 +197,13 @@ function ($scope, $stateParams, $state, $location, $anchorScroll, Service, Servi MaxAttempts: service.RestartMaxAttempts, Window: service.RestartWindow }; + + service.Ports.forEach(function (binding) { + if (binding.PublishedPort === null || binding.PublishedPort === '') { + delete binding.PublishedPort; + } + }); + config.EndpointSpec = { Mode: config.EndpointSpec.Mode || 'vip', Ports: service.Ports