Running a Dockerfile as a non-root user is a good practice for security reasons. By default, Docker runs containers with root privileges, but you can configure your Dockerfile to run as a non-root user.
Prerequisites
- Docker
Solution
Example Dockerfile:
FROM <some-base-image>
RUN groupadd -r myappgroup && useradd -r -g myappgroup myappuser
WORKDIR /app
COPY --chown:myappuser:myappgroup . .
USER myappuser
CMD <some-non-root-command>
Conclusion
In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.