Run a throwaway container with the current folder mounted

Try a tool, a Node version or a Python version without installing anything.

SNP 125 #A45 Filed docker cmd

shell
docker run --rm -it -v "$PWD":/app -w /app node:22 bash
  • --rm deletes the container when you exit
  • -it gives you an interactive shell
  • -v "$PWD":/app mounts the current folder at /app
  • -w /app starts you there

Inside, npm install and npm test work on your actual files. Everything you install into the image is gone when you leave; everything you write to /app stays.

The same trick for a one-off command:

shell
docker run --rm -v "$PWD":/app -w /app python:3.12 python script.py

On Linux, files created inside are owned by root. Add -u "$(id -u):$(id -g)" to avoid that.