I have been trying to use docker volume to persist my app. I'm new to docker and I am doing this on a mac. Every time I run my docker command I get an error saying my workdir is "invalid mode". Any help would be appreciated
This is my docker file
FROM node:18-alpine
WORKDIR /usr/app
COPY . .
RUN npm install
CMD [ "npm", "run", "start" ]
EXPOSE 5200
Running my image with this
docker run -p 5200:5200 -it --name server -v $(pwd):/usr/app -v /usr/app/node_modules server-docker
This is the error i receive
docker: Error response from daemon: invalid mode: /usr/app.
See 'docker run --help'.
The issue here is with your Docker volume mount syntax in this part: -v /usr/app/node_modules. Docker is expecting the volume mount syntax to be in the form :, but in your command, it appears that the container directory path is missing.
You're already mounting the current directory ($(pwd)) into /usr/app in the container. You should never mount node_modules into the container because node_modules directory get created when you docker run the npm run install command from the dockerfile.
Best solution would be to create .dockerignore
file on the location where dockerfile is and add node_modules to the ignore list like this to the .dockerignore
file.
node_modules
After that you can run following command to start the container.
docker run -p 5200:5200 -it --name server -v $(pwd):/usr/app server-docker
I would suggest to learn multistage build and about dockerignore
. Just google it for node or whatever framework you are using.