Node_modules versus Docker

I’ve encountered strange error lately. Whenever I tried  to run npm install in my project’s folder, it failed. The error says something about not being able to unlink folder. The interesting think was that it only happened under certain circumstances.

The reason for this was the when I started docker compose up to run my project in Docker, it created some lock on the node_modules folder. And shutting down the container or even the whole Docker did not help. The lock stayed there.

The only way to workaround this (at least which I am aware of) is to restart the whole machine and then run npm install again. Notice that Docker for Windows starts when you log in, but the lock was created only after I started docker compose.

If there is someone who knows a solution, I would be glad.