Everyone has their personal favorite, and this is mine:
RUN useradd --user-group --system --create-home --no-log-init app
USER app
Reference: man useradd
The RUN
line will add the user and group app
:
root@ef3e54b60048:/# id app
uid=999(app) gid=999(app) groups=999(app)
Use a more specific name than app
if the image is to be reused as a base image. As an aside, include --shell /bin/bash
if you really need.
Partial credit: answer by Ryan M