directory structure
projectroot/
docker-compose.yml
frontend/
Dockerfile
src/
node_modules
package.json
....
projectroot/frontend/docker-compose.yml
services:
frontend:
build: ./frontend
ports:
- 3000:3000
volumes:
- ./frontend/src:/app/
Dockerfile
FROM node:12.18.3
COPY /src/package.json .
RUN npm install --save-dev
COPY /src .
EXPOSE 3000
CMD ["npm", "run", "dev"]
The above works. I can run docker-compose up
and my app is rendered on localhost:3000
.
However when I make a change on projectroot/frontend/pages/index.js, that change isn't reflected.
I am confused because I copy the contents of /src over to /app in my Dockerfile ( COPY /src .
). If I run the container and bash in, I see /app
folder with the contents of my host /src
folder.
If I remove the COPY
command from Dockerfile
, the readout just loops the following:
$ docker-compose up
Recreating pricey_frontend_1 ... done
Attaching to pricey_frontend_1
frontend_1 |
frontend_1 | > src@1.0.0 dev /
frontend_1 | > cross-env NODE_ENV=development nodemon server.js
frontend_1 |
frontend_1 | [nodemon] 2.0.4
frontend_1 | [nodemon] to restart at any time, enter `rs`
frontend_1 | [nodemon] watching path(s): *.*
frontend_1 | [nodemon] watching extensions: js,mjs,json
frontend_1 | [nodemon] starting `npm run dev server.js`
frontend_1 |
frontend_1 | > src@1.0.0 dev /
frontend_1 | > cross-env NODE_ENV=development nodemon server.js "server.js"
*** loops until I kill it***
In my head, removing COPY makes sense because I want to use the host volume src (so that I can update it and the changes reflected on localhost:3000 immediately. What am I missing?
在这里检查这个答案我添加--legacy-watch
,现在它正在响应更改。
ENTRYPOINT [ "nodemon", "--legacy-watch", "--inspect=0.0.0.0", "./src/server.js"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.