Please follow this reasoning and tell me where I am wrong.
- I want to develop a web app with Typescript. This is the folder structure:
src
- index.ts
package.json
tsconfig.json
I want to compile and run the app inside a container so that is not environment-dependent.
I run
docker build --name my_image
with the followingDockerfile
in order to create an image:
FROM node:16
WORKDIR /app
COPY package.json /app
RUN npm install
CMD ["npx", "dev"]
This will create a
node_modules
folder inside the container.Now I create a container like so:
docker create -v $(pwd)/src/:/app/src my_image --name my_container
I created a volume so that when I change files in my host
/src
I will change also the same files in the container.I start the container like so:
docker start -i my_container
Now everything is working. The problem, though, are the linters.
When I open a file with my text editor from the host machine in
/src
the linter are not working because there is nonode_modules
installed on the host.
If I npm install
also on the host machine I will have 2 different node_modules
installation and there might be some compilation that differ between the host and the container.
Is there a way to point the host node_modules
to the container node_modules
?
If I create a docker volume
for node_modules
like so
docker create -v $(pwd)/node_modules:/app/node_modules ...
I will delete all the compilation done in the container.
What am I doing wrong?
Thank you.