Skip to content

Commit

Permalink
Adds instructions for modifying the node user (nodejs#328)
Browse files Browse the repository at this point in the history
Also highlights the `Best Practices` section in the `README.md` file so
the new instructions are easier to find.

Special thanks to:
* @blueimp for the uid/gid change command
* @LaurentGoderre for the user rename command

Refs nodejs#289
  • Loading branch information
sdwolfz authored and SimenB committed Jul 25, 2017
1 parent bc4e7ee commit c3694d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ It also assumes that you have a file named [`.dockerignore`](https://docs.docker
node_modules
```

## Best Practices

We have assembled a [Best Practices Guide](./docs/BestPractices.md) for those using these images on a daily basis.

## Run a single Node.js script
Expand Down
32 changes: 32 additions & 0 deletions docs/BestPractices.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@ FROM node:6.10.3
USER node
```

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.

If you do not want nor need the user created in this image you can remove it with the following:

```Dockerfile
# For debian based images use:
RUN userdel -r node

# For alpine based images use:
RUN deluser --remove-home node
```

If you need to change the uid/gid of the user you can use:

```Dockerfile
RUN groupmod -g 999 node && usermod -u 999 -g 999 node
```

If you need another name for the user (ex. `myapp`) execute:

```Dockerfile
RUN usermod -d /home/myapp -l myapp node
```

For alpine based images, you do not have `groupmod` nor `usermod`, so to change the uid/gid you have to delete the previous user:
```Dockerfile
RUN deluser --remove-home node \
&& delgroup node \
&& addgroup -S node -g 999 \
&& adduser -S -g node -u 999 node
```

## Memory

By default, any Docker Container may consume as much of the hardware such as CPU and RAM. If you are running multiple containers on the same host you should limit how much memory they can consume.
Expand Down

0 comments on commit c3694d8

Please sign in to comment.