Skip to content

Can I change the username of the node user inside the Dockerfile to "dev"? Will that break things? #5125

Closed

Description

@Nefcanto

Node.js Version

v24.12.0

NPM Version

11.7.0

Operating System

Linux api 6.14.0-37-generic #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 20 10:25:38 UTC 2 x86_64 GNU/Linux

Subsystem

Other

Description

I want to have a user inside the Docker container with UID 1000 and GID 1000.

I'm already using this Dockerfile:

https://github.com/nodejs/docker-node/blob/main/24/trixie-slim/Dockerfile

I see that the node user is created with that UID and GID.

What if I rename that use to dev? Does that break anything?

Minimal Reproduction

No response

Output

No response

Before You Submit

  • I have looked for issues that already exist before submitting this
  • My issue follows the guidelines in the README file, and follows the 'How to ask a good question' guide at https://stackoverflow.com/help/how-to-ask
Pinned by MikeMcC399

Activity

  1. avivkeller commented on Dec 29, 2025

    @avivkeller
    Member

    @nodejs/docker

  2. nschonni commented on Dec 29, 2025

    @nschonni
    Member
  3. Nefcanto commented on Dec 30, 2025

    @Nefcanto
    Author

    @nschonni I read that part. I just want to change the name of the user. This is my core image:

    FROM node:lts-trixie-slim
    
    RUN usermod -d /home/dev -l dev node
    
    RUN sed -i 's/^Components: main$/& contrib non-free-firmware/' /etc/apt/sources.list.d/debian.sources \
        && apt-get update -qq -y \
        && apt-get upgrade -qq -y \
        && apt-get install -y --no-install-recommends \
            git procps curl inotify-tools jq python3 make g++ unzip bc jo \
        && npm install --location=global npm npm-check \
        && cd /usr/local/bin && curl -fsSL https://getmic.ro | bash \
        && apt-get clean && rm -rf /var/lib/apt/lists/*
    
    USER dev
    
    WORKDIR /home/dev
    

    It builds. No problem. But then I have this panel image that uses my core image:

    FROM nefcanto/core:latest
    
    ENV PATH="${PATH}:/core/commands/panel:/core/commands"
    
    RUN npm install --location=global serve -y
    
    RUN echo DefaultLimitNOFILE=65536 > /etc/systemd/system.conf
    RUN echo DefaultLimitNOFILE=65536 > /etc/systemd/user.conf
    
    RUN ulimit -n 65536
    

    It fails when I add RUN usermod -d /home/dev -l dev node line. This is the permission error:

    #6 [2/5] RUN npm install --location=global serve -y
    #6 3.422 npm error code EACCES
    #6 3.423 npm error syscall mkdir
    #6 3.423 npm error path /usr/local/lib/node_modules/serve
    #6 3.423 npm error errno -13
    #6 3.425 npm error Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/serve'
    #6 3.425 npm error     at async mkdir (node:internal/fs/promises:861:10)
    #6 3.425 npm error     at async /usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:572:20
    #6 3.425 npm error     at async Promise.allSettled (index 0)
    #6 3.425 npm error     at async #reifyPackages (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:309:11)
    #6 3.425 npm error     at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:121:5)
    #6 3.425 npm error     at async Install.exec (/usr/local/lib/node_modules/npm/lib/commands/install.js:150:5)
    #6 3.425 npm error     at async Npm.exec (/usr/local/lib/node_modules/npm/lib/npm.js:208:9)
    #6 3.425 npm error     at async module.exports (/usr/local/lib/node_modules/npm/lib/cli/entry.js:67:5) {
    #6 3.425 npm error   errno: -13,
    #6 3.425 npm error   code: 'EACCES',
    #6 3.425 npm error   syscall: 'mkdir',
    #6 3.425 npm error   path: '/usr/local/lib/node_modules/serve'
    #6 3.425 npm error }
    #6 3.426 npm error
    #6 3.426 npm error The operation was rejected by your operating system.
    #6 3.426 npm error It is likely you do not have the permissions to access this f
    

    When I run it as node user, both images are built. But when I change the username to dev it seems that the permissions are broken. Do you have any idea why?

  4. LegendCo commented on Jun 17, 2026

    @LegendCo

    In general, renaming the node user to dev will not inherently break Node.js itself. Linux processes care about the numeric UID/GID much more than the username. If the user remains UID 1000 and GID 1000, most software will continue to work exactly the same way.

    If you're building on top of the official image, it's often simpler to leave the node user as-is and just use:

    USER node

  5. MikeMcC399 commented on Aug 10, 2026

    @MikeMcC399

    https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#non-root-user in #5125 (comment) already provided the answer:

    Note that the node user is neither a build-time nor a run-time dependency and it can be removed or altered, as long as the functionality of the application you want to add to the container does not depend on it.

  6. added
    answered🎉 Yay! The issue has been resolved, or the question has been answered.
    on Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    answered🎉 Yay! The issue has been resolved, or the question has been answered.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions