mirror of https://github.com/portainer/portainer
fix(container-details): recreate container with multiple networks (#1907)
* fix(container): Use first network's Mac address by default * fix(container): Connect additional networks to container after creation * fix(container): Remove warning messagepull/1946/head
parent
9bb885629a
commit
4429c6a160
|
@ -19,6 +19,8 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
||||||
NodeName: null
|
NodeName: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.extraNetworks = {};
|
||||||
|
|
||||||
$scope.state = {
|
$scope.state = {
|
||||||
formValidationError: '',
|
formValidationError: '',
|
||||||
actionInProgress: false
|
actionInProgress: false
|
||||||
|
@ -317,7 +319,7 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
||||||
var bindings = [];
|
var bindings = [];
|
||||||
for (var p in $scope.config.HostConfig.PortBindings) {
|
for (var p in $scope.config.HostConfig.PortBindings) {
|
||||||
if ({}.hasOwnProperty.call($scope.config.HostConfig.PortBindings, p)) {
|
if ({}.hasOwnProperty.call($scope.config.HostConfig.PortBindings, p)) {
|
||||||
var hostPort = '';
|
var hostPort = '';
|
||||||
if ($scope.config.HostConfig.PortBindings[p][0].HostIp) {
|
if ($scope.config.HostConfig.PortBindings[p][0].HostIp) {
|
||||||
hostPort = $scope.config.HostConfig.PortBindings[p][0].HostIp + ':';
|
hostPort = $scope.config.HostConfig.PortBindings[p][0].HostIp + ':';
|
||||||
}
|
}
|
||||||
|
@ -387,7 +389,16 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
||||||
}
|
}
|
||||||
$scope.config.NetworkingConfig.EndpointsConfig[$scope.config.HostConfig.NetworkMode] = d.NetworkSettings.Networks[$scope.config.HostConfig.NetworkMode];
|
$scope.config.NetworkingConfig.EndpointsConfig[$scope.config.HostConfig.NetworkMode] = d.NetworkSettings.Networks[$scope.config.HostConfig.NetworkMode];
|
||||||
// Mac Address
|
// Mac Address
|
||||||
$scope.formValues.MacAddress = d.NetworkSettings.Networks[$scope.config.HostConfig.NetworkMode].MacAddress;
|
if(Object.keys(d.NetworkSettings.Networks).length) {
|
||||||
|
var firstNetwork = d.NetworkSettings.Networks[Object.keys(d.NetworkSettings.Networks)[0]];
|
||||||
|
$scope.formValues.MacAddress = firstNetwork.MacAddress;
|
||||||
|
$scope.config.NetworkingConfig.EndpointsConfig[$scope.config.HostConfig.NetworkMode] = firstNetwork;
|
||||||
|
$scope.extraNetworks = angular.copy(d.NetworkSettings.Networks);
|
||||||
|
delete $scope.extraNetworks[Object.keys(d.NetworkSettings.Networks)[0]];
|
||||||
|
} else {
|
||||||
|
$scope.formValues.MacAddress = '';
|
||||||
|
}
|
||||||
|
|
||||||
// ExtraHosts
|
// ExtraHosts
|
||||||
if ($scope.config.HostConfig.ExtraHosts) {
|
if ($scope.config.HostConfig.ExtraHosts) {
|
||||||
var extraHosts = $scope.config.HostConfig.ExtraHosts;
|
var extraHosts = $scope.config.HostConfig.ExtraHosts;
|
||||||
|
@ -604,14 +615,24 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
||||||
};
|
};
|
||||||
|
|
||||||
function createContainer(config, accessControlData) {
|
function createContainer(config, accessControlData) {
|
||||||
|
var containerIdentifier;
|
||||||
$q.when(!$scope.formValues.alwaysPull || ImageService.pullImage($scope.config.Image, $scope.formValues.Registry, true))
|
$q.when(!$scope.formValues.alwaysPull || ImageService.pullImage($scope.config.Image, $scope.formValues.Registry, true))
|
||||||
.finally(function final() {
|
.finally(function final() {
|
||||||
ContainerService.createAndStartContainer(config)
|
ContainerService.createAndStartContainer(config)
|
||||||
.then(function success(data) {
|
.then(function success(data) {
|
||||||
var containerIdentifier = data.Id;
|
containerIdentifier = data.Id;
|
||||||
var userId = Authentication.getUserDetails().ID;
|
var userId = Authentication.getUserDetails().ID;
|
||||||
return ResourceControlService.applyResourceControl('container', containerIdentifier, userId, accessControlData, []);
|
return ResourceControlService.applyResourceControl('container', containerIdentifier, userId, accessControlData, []);
|
||||||
})
|
})
|
||||||
|
.then(function success() {
|
||||||
|
if($scope.extraNetworks) {
|
||||||
|
return $q.all(
|
||||||
|
Object.keys($scope.extraNetworks).map(function(networkName) {
|
||||||
|
return NetworkService.connectContainer(networkName, containerIdentifier);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('Container successfully created');
|
Notifications.success('Container successfully created');
|
||||||
$state.go('docker.containers', {}, {reload: true});
|
$state.go('docker.containers', {}, {reload: true});
|
||||||
|
|
|
@ -126,11 +126,6 @@
|
||||||
<span ng-hide="state.actionInProgress">Deploy the container</span>
|
<span ng-hide="state.actionInProgress">Deploy the container</span>
|
||||||
<span ng-show="state.actionInProgress">Deployment in progress...</span>
|
<span ng-show="state.actionInProgress">Deployment in progress...</span>
|
||||||
</button>
|
</button>
|
||||||
<span class="text-danger" ng-if="state.formValidationError" style="margin-left: 5px;">{{ state.formValidationError }}</span>
|
|
||||||
<span ng-if="fromContainerMultipleNetworks" style="margin-left: 10px">
|
|
||||||
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
|
|
||||||
<span class="small text-muted" style="margin-left: 5px;">This container is connected to multiple networks, only one network will be kept at creation time.</span>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- !actions -->
|
<!-- !actions -->
|
||||||
|
|
Loading…
Reference in New Issue