mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-18 17:00:25 +00:00
Make sure the PORT env var is a valid port number before trying to bind it.
This commit is contained in:
parent
9ca8077daa
commit
ab642470ec
@ -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)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user