From ab642470ec2b4b948e29e118a66ca3934028c0ea Mon Sep 17 00:00:00 2001 From: Page Date: Tue, 6 May 2014 17:36:30 +0100 Subject: [PATCH] Make sure the PORT env var is a valid port number before trying to bind it. --- src/application.coffee | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/application.coffee b/src/application.coffee index 97e5f9c4..090ff5a0 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -65,7 +65,11 @@ exports.start = start = (app) -> console.log("Creating container:", app.imageId) ports = {} 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( Image: app.imageId Cmd: ['/bin/bash', '-c', '/start'] @@ -74,19 +78,19 @@ exports.start = start = (app) -> Env: _.map app.env, (v, k) -> k + '=' + v ExposedPorts: ports ) - .then (container) -> - console.log('Starting container:', app.imageId) - ports = {} - if app.env.PORT? - ports[app.env.PORT + '/tcp'] = [ HostPort: app.env.PORT ] - container.startAsync( - Privileged: true - PortBindings: ports - Binds: [ - '/dev:/dev' - '/var/run/docker.sock:/run/docker.sock' - ] - ) + .then (container) -> + console.log('Starting container:', app.imageId) + ports = {} + if port? + ports[port + '/tcp'] = [ HostPort: port ] + container.startAsync( + Privileged: true + PortBindings: ports + Binds: [ + '/dev:/dev' + '/var/run/docker.sock:/run/docker.sock' + ] + ) .tap -> console.log('Started container:', app.imageId)