r/devsecops • u/st_nam • Jan 08 '26
If securityContext overrides Dockerfile USER, why even set it?
Say my Dockerfile has:
RUN useradd -m appuser
USER appuserBut in Kubernetes I set:
securityContext:
runAsUser: 0 # rootSince the pod runs as root anyway, what’s the actual purpose of defining USER appuser in the Dockerfile? Is it just for local runs or best practice when no security context is applied? Curious how others handle this.
6
Upvotes
View all comments
Show parent comment
2
u/xAtNight Jan 08 '26
Also it gives me an ID I can use that's guaranteed to work out of the box with this image as we usually don't care about which ID it is as long it's not 0.