Search code examples
dockerwindows-10docker-volume

Docker volume mapping to current working directory not work


Docker version 20.10.21

docker run command with -v option works as expected when the destination path is other than /app. But when the destination path is /app it doesn't work as expected.

command works as expected:

  docker run -d  -v ${pwd}:/app2 react-app

command not works as expected:

docker run -d  -v ${pwd}:/app react-app

as seen in the snapshot there is not port for the second container enter image description here

here is Dockerfile content

FROM node:14.16.0-alpine3.13
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
RUN mkdir data
COPY package*.json .
RUN npm install
COPY . .
ENV API_URL=http://api.myapp.com/
EXPOSE 3000
CMD [ "npm", "start" ]

Solution

  • I solved it by excluding the node_modules from the mounting as:

    docker run -d  -v ${pwd}:/app -v /app/node_modules  react-app
    

    If the port not mapped to the host in the dockerfile use this:

    docker run -d -p 3000:3000 -v ${pwd}:/app -v /app/node_modules  react-app