Make sure the PORT env var is a valid port number before trying to bind it.

This commit is contained in:
Page 2014-05-06 17:36:30 +01:00 committed by Pablo Carranza Vélez
parent 9ca8077daa
commit ab642470ec

View File

@ -65,7 +65,11 @@ exports.start = start = (app) ->
console.log("Creating container:", app.imageId) console.log("Creating container:", app.imageId)
ports = {} ports = {}
if app.env.PORT? if app.env.PORT?
ports[app.env.PORT + '/tcp'] = {} maybePort = parseInt(app.env.PORT, 10)
if parseFloat(app.env.PORT) is maybePort and maybePort > 0 and maybePort < 65535
port = maybePort
if port?
ports[port + '/tcp'] = {}
docker.createContainerAsync( docker.createContainerAsync(
Image: app.imageId Image: app.imageId
Cmd: ['/bin/bash', '-c', '/start'] Cmd: ['/bin/bash', '-c', '/start']
@ -74,19 +78,19 @@ exports.start = start = (app) ->
Env: _.map app.env, (v, k) -> k + '=' + v Env: _.map app.env, (v, k) -> k + '=' + v
ExposedPorts: ports ExposedPorts: ports
) )
.then (container) -> .then (container) ->
console.log('Starting container:', app.imageId) console.log('Starting container:', app.imageId)
ports = {} ports = {}
if app.env.PORT? if port?
ports[app.env.PORT + '/tcp'] = [ HostPort: app.env.PORT ] ports[port + '/tcp'] = [ HostPort: port ]
container.startAsync( container.startAsync(
Privileged: true Privileged: true
PortBindings: ports PortBindings: ports
Binds: [ Binds: [
'/dev:/dev' '/dev:/dev'
'/var/run/docker.sock:/run/docker.sock' '/var/run/docker.sock:/run/docker.sock'
] ]
) )
.tap -> .tap ->
console.log('Started container:', app.imageId) console.log('Started container:', app.imageId)