Reputation: 167
I have the files
...
example:
build:
context: ./example
ports:
- 3300:3000
networks:
- backend
volumes:
- ../example/:/var/www
container_name: example
...
FROM node:16
WORKDIR /var/www
RUN npm install -g react-scripts
RUN npm install
EXPOSE 3000
CMD [ "npm", "start" ]
When I run
docker-compose build
Get this error
...
npm ERR! path /var/www/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/var/www/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
But if I comment on the #RUN npm install
, the script sees package.json and "npm start" working, but I get error, because there are no node_modules
Where are the contents of the mounted folder, when "npm install"?
Upvotes: 1
Views: 4634
Reputation: 167
Thanks to David Maze, he gave food for the mind.
After several decisions, the best thing for me is the following
...
example:
build:
context: ./example
ports:
- 3300:3000
volumes:
- ./example/:/var/www
container_name: example
...
FROM node:16
WORKDIR /var/www
RUN npm install -g react-scripts
RUN chown -Rh node:node /var/www
USER node
EXPOSE 3000
CMD [ "sh", "-c", "npm install && npm run start" ]
This solution is great for development.
The user node
will help you with the rights of host<->guest
The folder node_modules
will be accessible from the host and synchronize host<->guest
Upvotes: 1