Docker hot reloading node app with nodemon using Windows 10
up vote
0
down vote
favorite
I have an express app and I'm trying to setup hot reloading with nodemon using docker for windows 10 as a dev environment. However when I npm install on the volume it doesn't seem to work.
With powershell I use a volume like so:
docker build -t node-api .
docker run --rm -it -p 8080:8080 -v "${PWD}:/usr/src/app" node-api
Which outputs this error:
[nodemon] 1.18.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server/server.js`
internal/modules/cjs/loader.js:605
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/usr/src/app/server/server.js:1:79)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
[nodemon] app crashed - waiting for file changes before starting...
If I exclude the -v flag and docker run then it starts with no errors, but doesn't detect changes or restart on file saves.
Dockerfile
FROM node:alpine
#Create app directory
WORKDIR /usr/src/app
#Install nodemon for hot reloading
RUN npm install nodemon -g
#Install app dependencies
#A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
RUN npm install
#Bundle app source
COPY . .
EXPOSE 8080
CMD [ "nodemon", "-L", "server/server.js" ]
Folder Structure
server/
>server.js
Dockerfile
package.json
Github repo for code
node.js windows docker express nodemon
add a comment |
up vote
0
down vote
favorite
I have an express app and I'm trying to setup hot reloading with nodemon using docker for windows 10 as a dev environment. However when I npm install on the volume it doesn't seem to work.
With powershell I use a volume like so:
docker build -t node-api .
docker run --rm -it -p 8080:8080 -v "${PWD}:/usr/src/app" node-api
Which outputs this error:
[nodemon] 1.18.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server/server.js`
internal/modules/cjs/loader.js:605
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/usr/src/app/server/server.js:1:79)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
[nodemon] app crashed - waiting for file changes before starting...
If I exclude the -v flag and docker run then it starts with no errors, but doesn't detect changes or restart on file saves.
Dockerfile
FROM node:alpine
#Create app directory
WORKDIR /usr/src/app
#Install nodemon for hot reloading
RUN npm install nodemon -g
#Install app dependencies
#A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
RUN npm install
#Bundle app source
COPY . .
EXPOSE 8080
CMD [ "nodemon", "-L", "server/server.js" ]
Folder Structure
server/
>server.js
Dockerfile
package.json
Github repo for code
node.js windows docker express nodemon
You overwrote thenode_modules
folder by mounting your whole windows folder into a linux docker container, thusexpress
and other deps are missing. You might want to only mountapp/src
or change your directory structure to allow that.
– William Chong
Nov 21 at 20:27
Hey William thanks for your help. I'm still a little confused could you show an example please? I tried mounting at various levels with no success. And I edited my question to include my folder structure - how would you fix it?
– Brayden Cowell
Nov 21 at 20:58
doesdocker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
work?
– William Chong
Nov 21 at 21:02
Yes that works! Thanks you so much
– Brayden Cowell
Nov 21 at 21:39
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an express app and I'm trying to setup hot reloading with nodemon using docker for windows 10 as a dev environment. However when I npm install on the volume it doesn't seem to work.
With powershell I use a volume like so:
docker build -t node-api .
docker run --rm -it -p 8080:8080 -v "${PWD}:/usr/src/app" node-api
Which outputs this error:
[nodemon] 1.18.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server/server.js`
internal/modules/cjs/loader.js:605
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/usr/src/app/server/server.js:1:79)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
[nodemon] app crashed - waiting for file changes before starting...
If I exclude the -v flag and docker run then it starts with no errors, but doesn't detect changes or restart on file saves.
Dockerfile
FROM node:alpine
#Create app directory
WORKDIR /usr/src/app
#Install nodemon for hot reloading
RUN npm install nodemon -g
#Install app dependencies
#A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
RUN npm install
#Bundle app source
COPY . .
EXPOSE 8080
CMD [ "nodemon", "-L", "server/server.js" ]
Folder Structure
server/
>server.js
Dockerfile
package.json
Github repo for code
node.js windows docker express nodemon
I have an express app and I'm trying to setup hot reloading with nodemon using docker for windows 10 as a dev environment. However when I npm install on the volume it doesn't seem to work.
With powershell I use a volume like so:
docker build -t node-api .
docker run --rm -it -p 8080:8080 -v "${PWD}:/usr/src/app" node-api
Which outputs this error:
[nodemon] 1.18.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server/server.js`
internal/modules/cjs/loader.js:605
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/usr/src/app/server/server.js:1:79)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
[nodemon] app crashed - waiting for file changes before starting...
If I exclude the -v flag and docker run then it starts with no errors, but doesn't detect changes or restart on file saves.
Dockerfile
FROM node:alpine
#Create app directory
WORKDIR /usr/src/app
#Install nodemon for hot reloading
RUN npm install nodemon -g
#Install app dependencies
#A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
RUN npm install
#Bundle app source
COPY . .
EXPOSE 8080
CMD [ "nodemon", "-L", "server/server.js" ]
Folder Structure
server/
>server.js
Dockerfile
package.json
Github repo for code
node.js windows docker express nodemon
node.js windows docker express nodemon
edited Nov 21 at 20:49
asked Nov 21 at 20:21
Brayden Cowell
204
204
You overwrote thenode_modules
folder by mounting your whole windows folder into a linux docker container, thusexpress
and other deps are missing. You might want to only mountapp/src
or change your directory structure to allow that.
– William Chong
Nov 21 at 20:27
Hey William thanks for your help. I'm still a little confused could you show an example please? I tried mounting at various levels with no success. And I edited my question to include my folder structure - how would you fix it?
– Brayden Cowell
Nov 21 at 20:58
doesdocker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
work?
– William Chong
Nov 21 at 21:02
Yes that works! Thanks you so much
– Brayden Cowell
Nov 21 at 21:39
add a comment |
You overwrote thenode_modules
folder by mounting your whole windows folder into a linux docker container, thusexpress
and other deps are missing. You might want to only mountapp/src
or change your directory structure to allow that.
– William Chong
Nov 21 at 20:27
Hey William thanks for your help. I'm still a little confused could you show an example please? I tried mounting at various levels with no success. And I edited my question to include my folder structure - how would you fix it?
– Brayden Cowell
Nov 21 at 20:58
doesdocker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
work?
– William Chong
Nov 21 at 21:02
Yes that works! Thanks you so much
– Brayden Cowell
Nov 21 at 21:39
You overwrote the
node_modules
folder by mounting your whole windows folder into a linux docker container, thus express
and other deps are missing. You might want to only mount app/src
or change your directory structure to allow that.– William Chong
Nov 21 at 20:27
You overwrote the
node_modules
folder by mounting your whole windows folder into a linux docker container, thus express
and other deps are missing. You might want to only mount app/src
or change your directory structure to allow that.– William Chong
Nov 21 at 20:27
Hey William thanks for your help. I'm still a little confused could you show an example please? I tried mounting at various levels with no success. And I edited my question to include my folder structure - how would you fix it?
– Brayden Cowell
Nov 21 at 20:58
Hey William thanks for your help. I'm still a little confused could you show an example please? I tried mounting at various levels with no success. And I edited my question to include my folder structure - how would you fix it?
– Brayden Cowell
Nov 21 at 20:58
does
docker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
work?– William Chong
Nov 21 at 21:02
does
docker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
work?– William Chong
Nov 21 at 21:02
Yes that works! Thanks you so much
– Brayden Cowell
Nov 21 at 21:39
Yes that works! Thanks you so much
– Brayden Cowell
Nov 21 at 21:39
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The problem is that by mounting the whole host app/
directory as volume, the app/node_modules/
inside the container would be overwritten by the host's app/
, thus all dependencies are missing.
The solution is to only mount the source code folder you need, i.e.
docker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The problem is that by mounting the whole host app/
directory as volume, the app/node_modules/
inside the container would be overwritten by the host's app/
, thus all dependencies are missing.
The solution is to only mount the source code folder you need, i.e.
docker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
add a comment |
up vote
1
down vote
accepted
The problem is that by mounting the whole host app/
directory as volume, the app/node_modules/
inside the container would be overwritten by the host's app/
, thus all dependencies are missing.
The solution is to only mount the source code folder you need, i.e.
docker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The problem is that by mounting the whole host app/
directory as volume, the app/node_modules/
inside the container would be overwritten by the host's app/
, thus all dependencies are missing.
The solution is to only mount the source code folder you need, i.e.
docker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
The problem is that by mounting the whole host app/
directory as volume, the app/node_modules/
inside the container would be overwritten by the host's app/
, thus all dependencies are missing.
The solution is to only mount the source code folder you need, i.e.
docker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
answered Nov 22 at 2:27
William Chong
826416
826416
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419922%2fdocker-hot-reloading-node-app-with-nodemon-using-windows-10%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You overwrote the
node_modules
folder by mounting your whole windows folder into a linux docker container, thusexpress
and other deps are missing. You might want to only mountapp/src
or change your directory structure to allow that.– William Chong
Nov 21 at 20:27
Hey William thanks for your help. I'm still a little confused could you show an example please? I tried mounting at various levels with no success. And I edited my question to include my folder structure - how would you fix it?
– Brayden Cowell
Nov 21 at 20:58
does
docker run --rm -it -p 8080:8080 -v "${PWD}/server:/usr/src/app/server" node-api
work?– William Chong
Nov 21 at 21:02
Yes that works! Thanks you so much
– Brayden Cowell
Nov 21 at 21:39