You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -19,14 +20,19 @@ For security reasons this is **must** be followed.
19
20
20
21
The container's **Dockerfile** and the **Pod resource file (yaml)** has to be modified to be able to run as a non-root user.
21
22
22
-
- Modify the image's Dockerfile with a `RUN` command that adds a non-root user and a `USER` command that specifies which user runs the container on startup. The example below can be modified for specific needs/requirements.
23
+
- First it is recommended to check how the base image is built to see if it
24
+
might already have a non-root user defined and used. In this case it is enough
25
+
to specify that user in the Dockerfile with the `USER` instruction.
26
+
- Otherwise modify the image's Dockerfile with a `RUN` command that adds a non-root user
27
+
and a `USER` command that specifies which user runs the container on startup.
28
+
The example below can be modified for specific needs/requirements.
23
29
24
30
```Dockerfile
25
31
#Pull the base image as Ubuntu
26
32
FROM ubuntu:latest
27
33
28
-
#Add a user with userid 8877 and name nonroot
29
-
RUN useradd −u 8877 nonroot
34
+
#Add a user with userid 1000 and name nonroot
35
+
RUN useradd −u 1000 nonroot
30
36
31
37
#Run Container as nonroot
32
38
USER nonroot
@@ -46,6 +52,5 @@ spec:
46
52
- name: example-container
47
53
image: gcr.io/google-samples/node-hello:1.0
48
54
securityContext:
49
-
runAsUser: 1000# SPECIFY USER ID HERE
50
55
allowPrivilegeEscalation: false # SET THIS TO FALSE
0 commit comments