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
By default, Docker runs commands inside the container as root which violates the [Principle of Least Privilege (PoLP)](https://en.wikipedia.org/wiki/Principle_of_least_privilege) when superuser permissions are not strictly required. You want to run the container as an unprivileged user whenever possible. The nonroot images provide the `nonroot` user for such purpose. The Docker Image can then be run with the `nonroot` user in the following way:
76
+
77
+
```
78
+
-u "nonroot"
79
+
```
80
+
81
+
Alternatively, the user can be activated in the `Dockerfile`:
82
+
83
+
```Dockerfile
84
+
FROM thehale/python-poetry:1.8.3
85
+
...
86
+
# At the end, set the user to use when running this image
87
+
USER nonroot
88
+
```
89
+
90
+
> [!TIP]
91
+
>
92
+
> When using the `nonroot` user, remember to assign the corresponding ownership
93
+
> to your application tree (e.g. `chmod`).
94
+
95
+
Note that the `nonroot` user is neither a build-time nor a run-time dependency
96
+
and it can be removed or altered, as long as the functionality of the
97
+
application you want to add to the container does not depend on it.
98
+
99
+
If you do not want nor need the user created in this image, you can remove it with the following:
100
+
101
+
```Dockerfile
102
+
# For debian based images use:
103
+
RUN userdel -r nonroot
104
+
105
+
# For alpine based images use:
106
+
RUN deluser --remove-home nonroot
107
+
```
108
+
109
+
If you need to change the uid/gid of the user, you can use:
0 commit comments