It always seems to take me a few attempts to get this right, so I’m making a note here:
docker run -it -v $PWD:/app -w /app node:12-alpine npm init
You may need to chown the package.json after (the docker daemon runs as root).
You can use the same thing to add packages:
docker run -it -v $PWD:/app -w /app node:12-alpine npm i --save foo