1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-22 14:59:41 +02:00

Added PortBindings to container start.

This commit is contained in:
Kevan Ahlquist 2015-01-18 23:20:49 -06:00
parent 77062bec84
commit 76d7e280f9
4 changed files with 128 additions and 4 deletions

View file

@ -9,7 +9,8 @@ function($scope, $routeParams, $location, Container, Messages) {
cpuShares: 1024,
env: '',
commands: '',
volumesFrom: ''
volumesFrom: '',
portBindings: []
};
$scope.commandPlaceholder = '["/bin/echo", "Hello world"]';
@ -27,6 +28,27 @@ function($scope, $routeParams, $location, Container, Messages) {
var loc = $location;
var s = $scope;
var exposedPorts = {};
var portBindings = {};
// TODO: consider using compatibility library
$scope.config.portBindings.forEach(function(portBinding) {
var intPort = portBinding.intPort + "/tcp";
var binding = {
HostIp: portBinding.ip,
HostPort: portBinding.extPort
};
if (portBinding.intPort) {
exposedPorts[intPort] = {};
if (intPort in portBindings) {
portBindings[intPort].push(binding);
} else {
portBindings[intPort] = [binding];
}
} else {
// TODO: Send warning message? Internal port need to be specified.
}
});
Container.create({
Image: id,
name: $scope.config.name,
@ -34,10 +56,19 @@ function($scope, $routeParams, $location, Container, Messages) {
MemorySwap: $scope.config.memorySwap,
CpuShares: $scope.config.cpuShares,
Cmd: cmds,
VolumesFrom: $scope.config.volumesFrom
VolumesFrom: $scope.config.volumesFrom,
ExposedPorts: exposedPorts,
HostConfig: {
PortBindings: portBindings
}
}, function(d) {
if (d.Id) {
ctor.start({id: d.Id}, function(cd) {
ctor.start({
id: d.Id,
HostConfig: {
PortBindings: portBindings
}
}, function(cd) {
$('#create-modal').modal('hide');
loc.path('/containers/' + d.Id + '/');
}, function(e) {
@ -50,4 +81,13 @@ function($scope, $routeParams, $location, Container, Messages) {
failedRequestHandler(e, Messages);
});
};
$scope.addPortBinding = function() {
$scope.config.portBindings.push({ip: '', extPort: '', intPort: ''});
};
$scope.removePortBinding = function(portBinding) {
var idx = $scope.config.portBindings.indexOf(portBinding);
$scope.config.portBindings.splice(idx, 1);
};
}]);