You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FROM node:latest
RUN npm i -g nodemon
USER node
RUN mkdir /home/node/code
WORKDIR /home/node/code
COPY --chown=node:node package-lock.json package.json ./
RUN npm ci
COPY --chown=node:node . .
CMD ["nodemon", "index.js"]
I guess the issue is, since we have copied the files into the docker, therefore by changing files in our editor, these changes wont end up inside the running docker, therefore nodemon see no changes and there will be no updates.
Therefore in order to make it react to our local files, we need to make the source code available to the docker by mounting it with the docker-compose:
v1:
volumes:
- ./api:/home/node/code # Mount host's ./api folder into the container and you have to make sure that you have node_module in /api folder of your editor,
The issue with version 1, is you may have some conflicts between the packages for your local machine and the docker os
v2:
volumes:
- ./api:/home/node/code # Mount your source code
- /home/node/code/node_modules # Don't overwrite node_modules directory of api docker image
The problem with version2 is, if you install a new lib or remove something from it, it wont gets updated in the node_module of your docker
v3:
volumes:
- ./api/index.js:/home/node/code/index.js # Mount host's ./api/index.js into the container
the problem with version 3 is like v2 and also is super limited.
Final version:
services:
api:
build: apiports:
- "8080:8080"links:
- dbenvironment:
MONGO_CONNECTION_STRING: mongodb://db:27017volumes:
- ./api:/home/node/code # Mount your source code
- /home/node/code/node_modules # Don't overwrite node_modules directory of api docker imagedb:
image: mongo:7web:
build: webports:
- "8081:80"
What is your suggestion?
The text was updated successfully, but these errors were encountered:
SeyyedKhandon
changed the title
nodemon in docker compose does not work
Reactive docker to source code changes: nodemon in docker compose does not work
Oct 13, 2024
I was trying to use the dockerfile config for nodemon from https://containers-v2.holt.courses/lessons/multi-container-projects/docker-compose , but it does not work,
I guess the issue is, since we have copied the files into the docker, therefore by changing files in our editor, these changes wont end up inside the running docker, therefore nodemon see no changes and there will be no updates.
Therefore in order to make it react to our local files, we need to make the source code available to the docker by mounting it with the docker-compose:
v1:
volumes: - ./api:/home/node/code # Mount host's ./api folder into the container and you have to make sure that you have node_module in /api folder of your editor,
The issue with version 1, is you may have some conflicts between the packages for your local machine and the docker os
v2:
volumes: - ./api:/home/node/code # Mount your source code - /home/node/code/node_modules # Don't overwrite node_modules directory of api docker image
The problem with version2 is, if you install a new lib or remove something from it, it wont gets updated in the node_module of your docker
v3:
volumes: - ./api/index.js:/home/node/code/index.js # Mount host's ./api/index.js into the container
the problem with version 3 is like v2 and also is super limited.
Final version:
What is your suggestion?
The text was updated successfully, but these errors were encountered: