Dockerfile entrypoint unable to switch user

if [ -n "$USER_ID" -a -n "$GROUP_ID" ]; then
    chown -R $USER_NAME:$GROUP_NAME .
    su $USER_NAME


exec "$@"

This is the entry point script which is supposed to change the user after changing the ownership of the directory. But the user is not getting changed, when I try to check the user running the container I always find root user running the container.

Please, help.

Depends on which linux flavour you are working with. You need to see “sudo” command is available. if you are working with alpine version then ideally this command should work

apk add sudo
su {your user name}