elwww
February 16, 2023, 10:24am
1
Hi, im trying to host a simple NodeJS app.
When running it. All ports I try are in use.
This is my Dockerfile:
FROM node:18.9.0
WORKDIR /app
ADD . /app
COPY . .
RUN npm install
RUN npm run build
EXPOSE 8080
CMD [ "node", "./index.mjs" ]
Fly IO config is default with also the app on port 8080.
No matter what port I try:
Error: listen EADDRINUSE: address already in use 127.0.0.1:8080
Also tried 0.0.0.0:8080 and ports 3000, 3030 and 1337.
Hi Elmar, could you please post the fly.toml
configuration and the index.mjs
code fragment responsible for starting the HTTP listener? You application should be accessible at <application-name>.fly.dev
, it not clear why you try to access it at 127.0.0.1
and 0.0.0.0
.
elwww
February 16, 2023, 11:36am
3
This is an error from the build logs when doing the health check. Im not trying to access the app from there. Its simply not deploying. When Fly tries to run the node app it says address is in use.
Fly.toml
# fly.toml file generated for zifera-marketing-site on 2023-02-15T14:17:28+01:00
app = "marketing-site"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[env]
PORT = 8080
[experimental]
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
Index.mjs
import express from 'express';
import { handler as ssrHandler } from './dist/server/entry.mjs';
const app = express();
app.use(express.static('dist/client/'))
app.use(ssrHandler);
app.listen(process.env.PORT || 8080);
The configuration and code look correct. Haven’t you tried to destroy the application using 'fly destroy <application_name>
and start deployment again?
elwww
February 16, 2023, 11:58am
5
Same problem
1 desired, 1 placed, 0 healthy, 1 unhealthy [restarts: 2]
Failed Instances
Failure #1
Instance
ID PROCESS VERSION REGION DESIRED STATUS HEALTH CHECKS RESTARTS CREATED
99fbcd86 app 0 ams run failed 2 16s ago
Recent Events
TIMESTAMP TYPE MESSAGE
2023-02-16T11:57:21Z Received Task received by client
2023-02-16T11:57:21Z Task Setup Building Task Directory
2023-02-16T11:57:23Z Started Task started by client
2023-02-16T11:57:25Z Terminated Exit Code: 1
2023-02-16T11:57:25Z Restarting Task restarting in 1.201671134s
2023-02-16T11:57:31Z Started Task started by client
2023-02-16T11:57:33Z Terminated Exit Code: 1
2023-02-16T11:57:33Z Restarting Task restarting in 1.121943241s
2023-02-16T11:57:38Z Started Task started by client
2023-02-16T11:57:40Z Terminated Exit Code: 1
2023-02-16T11:57:40Z Not Restarting Exceeded allowed attempts 2 in interval 5m0s and mode is "fail"
2023-02-16T11:57:40Z Alloc Unhealthy Unhealthy because of failed task
2023-02-16T11:57:40Z Killing Sent interrupt. Waiting 5s before force killing
2023-02-16T11:57:31Z [info]}
2023-02-16T11:57:31Z [info]Node.js v18.9.0
2023-02-16T11:57:32Z [info]Starting clean up.
2023-02-16T11:57:37Z [info]Starting instance
2023-02-16T11:57:37Z [info]Configuring virtual machine
2023-02-16T11:57:37Z [info]Pulling container image
2023-02-16T11:57:37Z [info]Unpacking image
2023-02-16T11:57:37Z [info]Preparing kernel init
2023-02-16T11:57:38Z [info]Configuring firecracker
2023-02-16T11:57:38Z [info]Starting virtual machine
2023-02-16T11:57:38Z [info]Starting init (commit: 617e840)...
2023-02-16T11:57:38Z [info]Preparing to run: `docker-entrypoint.sh node ./index.mjs` as root
2023-02-16T11:57:38Z [info]2023/02/16 11:57:38 listening on [fdaa:0:bfa5:a7b:23c2:99fb:cd86:2]:22 (DNS: [fdaa::3]:53)
2023-02-16T11:57:39Z [info]Server listening on http://127.0.0.1:8080
2023-02-16T11:57:39Z [info]node:internal/errors:484
2023-02-16T11:57:39Z [info] ErrorCaptureStackTrace(err);
2023-02-16T11:57:39Z [info] ^
2023-02-16T11:57:39Z [info]Error: listen EADDRINUSE: address already in use 127.0.0.1:8080
2023-02-16T11:57:39Z [info] at Server.setupListenHandle [as _listen2] (node:net:1485:16)
2023-02-16T11:57:39Z [info] at listenInCluster (node:net:1533:12)
2023-02-16T11:57:39Z [info] at doListen (node:net:1682:7)
2023-02-16T11:57:39Z [info] at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
2023-02-16T11:57:39Z [info] code: 'EADDRINUSE',
2023-02-16T11:57:39Z [info] errno: -98,
2023-02-16T11:57:39Z [info] syscall: 'listen',
2023-02-16T11:57:39Z [info] address: '127.0.0.1',
2023-02-16T11:57:39Z [info] port: 8080
2023-02-16T11:57:39Z [info]}
2023-02-16T11:57:39Z [info]Node.js v18.9.0
2023-02-16T11:57:39Z [info]Starting clean up.
--> v0 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v1
Thanks for the log, probably there is something with setupListenHandle
:
Could you try to run something simple as:
import express from 'express';
const app = express();
app.listen(8080)
app.get('/', (req, res) => {
res.send('Hello!')
})