Skip to content

Commit fef7a2c

Browse files
authored
Merge pull request #264 from LaurentGoderre/docs
Updated the non-root section of the Best Practices
2 parents 75b8ce9 + 435636a commit fef7a2c

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

docs/BestPractices.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ Run with `NODE_ENV` set to `production`. This is the way you would pass in secre
1010

1111
## Non-root User
1212

13-
By default, Docker runs container as root which inside of the container can pose as a security issue. You would want to run the container as an unprivileged user wherever possible. This is however not supported out of the box with the `node` Docker image.
13+
By default, Docker runs container as root which inside of the container can pose as a security issue. You would want to run the container as an unprivileged user wherever possible. The node images (with the exception of the `onbuild` variant) provide the `node` user for such purpose. The Docker Image can than be run with the `app` user in the following way:
1414

15-
```Dockerfile
16-
FROM node:4.1.2
17-
# Add our user and group first to make sure their IDs get assigned consistently
18-
RUN groupadd -r app && useradd -r -g app app
1915
```
20-
21-
This Docker Image can than be run with the `app` user in the following way:
22-
16+
-u "node"
2317
```
24-
-u "app"
18+
When using the `onbuild` variant, add the user like so:
19+
20+
```Dockerfile
21+
FROM node:4.1.2-onbuild
22+
# Add our user and group first to make sure their IDs get assigned consistently
23+
RUN groupadd -r node && useradd -r -g node node
2524
```
2625

2726
#### Memory
@@ -42,12 +41,12 @@ CMD ["node","index.js"]
4241

4342
## Docker Run
4443

45-
Here is an example of how you would run a default Node.JS Docker Containerized application:
44+
Here is an example of how you would run a default Node.JS Docker Containerized application:
4645

4746
```
4847
$ docker run \
4948
-e "NODE_ENV=production" \
50-
-u "app" \
49+
-u "node" \
5150
-m "300M" --memory-swap "1G" \
5251
-w "/usr/src/app" \
5352
--name "my-nodejs-app" \

0 commit comments

Comments
 (0)