I have the problem with installing node_modules
inside the Docker container and synchronize them with the host. My Docker\'s version is 18.03.1-ce, build
Having run into this issue and finding the accepted answer pretty slow to copy all node_modules
to the host in every container run, I managed to solve it by installing the dependencies in the container, mirror the host volume, and skip installing again if a node_modules
folder is present:
Dockerfile:
FROM node:12-alpine
WORKDIR /usr/src/app
CMD [ -d "node_modules" ] && npm run start || npm ci && npm run start
docker-compose.yml:
version: '3.8'
services:
service-1:
build: ./
volumes:
- ./:/usr/src/app
When you need to reinstall the dependencies just delete node_modules
.