How to switch user(su) in docker command

You need to use security context as like below

   securityContext:
     runAsUser: 1000
     runAsGroup: 3000
     fsGroup: 2000

Reference: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#podsecuritycontext-v1-core

enter image description here


EDIT:

If you wanted to change the user in you container than, you can add extra layer of dockerfile, check below

Add dockerfile layer,

   FROM <your_image>
   RUN adduser newuser
   USER newuser
   :       
   :

Now use above custom image in your kubernetes.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top