nodemon: nodemon with babel-node in docker address already in use
I configured a simple app in express to run in a docker container but whenever I make a change nodemon gives me an error saying that the port is already in use.
Error: listen EADDRINUSE: address already in use :::4000
That is my start script: nodemon -L --exec babel-node -- src/index
"nodemon": "^1.18.7"
and my index.js:
import express from 'express'
const app = express();
app.get("/", (req, res) => {
res.send("hello world");
});
app.listen(4000, () => console.log("The server is listening on port 4000"));
It’s like it’s not closing the process and it’s trying to execute again
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 13
- Comments: 50 (6 by maintainers)
I’m having the same issue when running with docker-compose. However, adding
--signal SIGINTto the nodemon command seems to fix it.Live fix in nodemon@1.18.8 (core change in pstree.remy…again).
I face the same issue and I believe somehow it is a
Docker+nodemon --execflag issueIn the following
package.json, if you replace:by:
it works perfectly under docker. Note that both work fine under OSX.
Here is the test case:
src/index.js
package.json
Dockerfile
docker-compose.yml
Note: I need
--execbecause I pipe the output in the bunyan parser like this--exec 'npm start' | bunyanin real use case.To add some more details on this issue, I’ve been using nodemon to hot reload my API inside docker for the past 2 months. It was worked extremely well with no issues. After I upgraded I began to experience OPs issue.
Modifying my command to use –signal SIGINT as suggested above didn’t solve the issue.
However, I tested my API outside of docker with and without –signal SIGINT and it reloads correctly in both scenarios.
I can’t debug much further right now but hopefully this bit of info can help.
I’m facing the same issue. This has started after I upgraded from
1.18.4to1.18.7. I think it could be related to #1476.Also I’m controlling the shutdown of my server with the approach described at https://github.com/remy/nodemon#controlling-shutdown-of-your-script but I don’t seem to ever receive
SIGUSR2.One more thing, if I start and immediately change a file I can clearly see the logs of 2 servers starting, the first one with success and the second one failing due to
EADDRINUSE. Quite clearly the process is not shutdown.I’ve tried to debug but I can’t seem to find much, not familiar with the nodemon codebase. @remy is there a build process if I change the source or I can just push the code to my fork and npm install from there?
Just add
--delay 300msinto the command solved my problem.https://github.com/remy/nodemon#delaying-restarting
Anyone else from the future visiting this, I had to make sure my volume was mounted in docker-compose.yml to get nodemon to find the files.
Same error using linux, docker, yarn and ts-node.
Dockerfile:
package.json:
Versions:
Error in terminal:
But if I exec into the running container I can’t find the blocking process:
Let’s wait for @remy to see what he has to say about that, the next steps.
I encountered this issue trying to get
nodemonto restart a development server in a docker container and after debugging it I discovered the issue was thepstree.remylibrary wasn’t able to generate a list of the child process subtree for termination so it only terminates the top level child (the shell which launches node) and orphans the actual node server. This happens because:psutil wasn’t installed by default in mynode:lts-slimdocker image./proc(which is the fallback for whenpsis unavailable).The solution for me was to install
psin my docker image:@timini not a real one. For now, just use the version
1.13.3all version after won’t work. Or if you use yarn you can add this in your package.json :As mention in https://github.com/remy/nodemon/issues/1484
@tibotiber I tried to reinstall the version
1.18.4but it didn’t solve the issue. But then I rollbacked to the version1.12.1and voilà ! I worked like a charm. So as a temporary fix you can do:Note: I didn’t checked all versions between
1.12.1and1.18.4@20k-ultra To my understanding under OSX docker is not using virtualbox with vboxsf since a long time so the
-Lto watch the filesystem is useless in this case. I got no idea if it is still required on Windows though… But this is not relevant to the issue since the-Lis use to make sure nodemon catches the file changes and tries to restart. Here it tries to restart but fail trying.@richardkall It’s still not working for me, I noticed that you are not using the legacy watch, for me if I don’t use
nodemondoesn’t work at all, specially now setting--signaleven with the legacy watch it’s not working either.btw: my settings are not that different from yours.
I noticed that it only works without
babel-node, if I change:import express from 'express'to:
const express = require('express')and use this as script:
"start": "nodemon -L src/index"It works, it doesn’t however when using
--execandbabel-node