Proper usage of 'sudo' in Dockerfiles

I’ve just started to use Docker more often for smaller projects I am working on. The issue I am having is that for setting up some environments/applications I need the capability to use sudo. I’ve tried different ways of piping the password to the commands requiring sudo in case that would work, however it does not. Another option would to just remove the requirement of entering a password when running sudo. Granted, my experience with linux is nothing to write home about. I’m looking for suggestions/advice/helpful articles that may help me get a solid answer to this problem.

In your Dockerfile you can freely USER root to switch the effective user for following commands, and in fact root is the default.

I’ve used gosu inside my containers. Works great.