u/shellscript_

Is using the non root docker node user for local dev overkill?
▲ 4 r/docker

Is using the non root docker node user for local dev overkill?

I'm learning fullstack and containers and am trying to follow best practices where I can. I'm on Debian and am developing locally using docker containers for Node, Django, and etc, and wiring them up together in one compose file.

I've noticed that a lot of places recommend using the prebuilt non root node user inside of a node container. I'm using this container like a VM, where I basically pull a blank trixie-slim node image down, add volumes, attach to it, install a new Vite React project, and let the volumes persist my settings and project files on the host.

This is the basic "from scratch" compose I've been using to get the volumes up and running before switching to my development compose file:

services:
  frontend:
    build:
      context: ./frontend
    volumes:
     - ./frontend:/usr/src/frontend
     - unprivileged_nodemodules_data:/usr/src/frontend/node_modules
    stdin_open: true
    tty: true

volumes:
  unprivileged_nodemodules_data:

I ran into some trouble with node_modules being owned by root, which I fixed by creating the directory as the node user in my dockerfile.

I guess my main question is if this is overkill. In a team setting, would this cause more problems than it's worth? Or is it actually a good practice? Should I just stick to running as root inside the development containers, since my prod container will be nginx running as the non root nginx user anyway?

u/shellscript_ — 5 days ago