Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes not being triggered on Docker #79

Closed
theprobugmaker opened this issue Dec 2, 2018 · 7 comments
Closed

Changes not being triggered on Docker #79

theprobugmaker opened this issue Dec 2, 2018 · 7 comments

Comments

@theprobugmaker
Copy link

theprobugmaker commented Dec 2, 2018

I have this simple setup for testing purposes:

Dockerfile:

FROM node:11.2.0-alpine
WORKDIR /usr/src/app
RUN yarn

docker-compose.yml:

version: "3.7"
services:
  server:
    build: .
    command: yarn start
    ports:
      - 4000:4000
    volumes:
      - .:/usr/src/app

index.js:

const express = require("express");

const app = express();

app.get("/", (req, res) => {
  res.send("hello world");
});

app.listen(4000, () => console.log("The server is listening on port 4000"));

In my package.json I have a script that is:

"scripts": {
  "start": "onchange -i -k **/*.js -- node index.js"
}

It does work locally in my computer, however when running in a Docker container it doesn't detect the changes and nothing happens.

@blakeembrey
Copy link
Collaborator

@zefexdeveloper So the file watcher is chokidar. I didn't find much on Docker, but I did find paulmillr/chokidar#590. Have you had any luck with chokidar directly or any other file watchers for node.js?

@theprobugmaker
Copy link
Author

@blakeembrey I haven't tried chokidar directly on docker to be honest. I was using nodemon with the legeacy watcher but I'm having a lot of problems with it and for that reason I'm looking for an alternative, I tried to use onchange (hoping it would work) but for some reason it doesn't.

@blakeembrey
Copy link
Collaborator

@zefexdeveloper Can you try https://github.com/Qard/onchange#poll--p-ms---poll-ms as a workaround for now? It might be an issue with the mounted directory in Docker so polling would be a workaround (I know Windows mounted partitions have a similar issue).

@theprobugmaker
Copy link
Author

@zefexdeveloper It's having the same problem as I was having with nodemon, it seems to not be closing the process and trying to open another one.

Error: listen EADDRINUSE: address already in use :::4000

remy/nodemon#1477

@blakeembrey
Copy link
Collaborator

@zefexdeveloper You're saying it isn't closing the previous process before starting a new process? That seems odd since it listens for exit on the process before spawning another, but I'll have to give it a go to replicate. Do you have a simple repo with the above configuration to get started there? I can do it myself too, but it may take a bit longer to get around to is all 😄

@theprobugmaker
Copy link
Author

@blakeembrey Yes, it's really weird, but it's like opening a new process and that is why it's saying that the port is already in use.
I don't have a repo with the configuration I sent, I can do that later (it's 4AM for me right now), or you can try in the mean time. (if possible)

@theprobugmaker
Copy link
Author

theprobugmaker commented Dec 12, 2018

@blakeembrey It was fixed in nodemon, the problem was in the ps tree, a module based on node-kill-tree, the same module you are using. That is how it was fixed:

remy/pstree@5f58daf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants