As I read in this tutorial https://mherman.org/blog/dockerizing-a-react-app/ it's possible to mount an anonymous volume into a subpath of a mounted volume in order to prevent the changes in that subpath to be reflected back to the actual volume. Is that correct? Because it's not working for me.
I'm trying to dockerize a react app by mounting the src
folder into the container and building everything their. But I don't want the node_modules
folder that is created during the build step to be reflected back in the mounted src
.
My Dockerfile.dev
looks like this:
FROM node:15.4.0-alpine3.12
# set working directory
ARG APP_PATH=/app
WORKDIR $APP_PATH
# add `/app/node_modules/.bin` to $PATH
ENV PATH $APP_PATH/node_modules/.bin:$PATH
# install app dependencies
COPY package*.json ./
RUN npm install --silent
# add app
COPY . ./
# start app
EXPOSE 3000
CMD [ "npm", "run", "start" ]
This is my docker-compose.yaml
:
version: "3.8"
services:
frontend:
build:
context: ./frontend
dockerfile: ../docker/Dockerfile.dev
image: frontend_react
ports:
- 4000:3000
volumes:
- ./frontend:/app
- /app/node_modules
environment:
- NODE_ENV=development
How can I prevent that the node_modules
folder shows up on my local machine?
Should I even prevent the node_modules
folder from being reflected back to my machine?