Running npm in a Separate Container when using Claude
A few weeks ago I wrote about running Claude in a container because I really don’t want it to have access to my computer. I mount a directory on my host into the container, and Claude can read and write files in that directory.
Some of the applications I had Claude create for me use Node, and I had it lock down the versions of the dependencies. To do this, it created a .npmrc that looks like this -
ignore-scripts=true
save-exact=trueThe next step in locking everything down is to generate a package-lock.json file. But I had to run npm install to generate this.
Now I need to install Node and npm, definitely not something I want to do on my computer, or even in the container that I run Claude in.
The workaround
I started a new container with the same mounts as the Claude container, giving it access to the source code. Then I installed Node and npm in that container and ran npm install to generate the package-lock.json file.
Here is the docker run command -
docker run -it --rm --mount type=bind,source=/home/bryan/dev/claude/,target=/root/dev alpineThen in the container, I installed Node and npm -
apk add nodejs npmNow I can run npm install to generate the package-lock.json file.
Close the container, Node and npm are gone, but the package-lock.json file is still there.
This same approach can be used for any other tools you need to run.
I love containers!