How to set root password?

I’m trying to deploy a web application that uses PAM as authentication method to access it, and even using the command line

RUN echo 'root:<some_password>' | chpasswd

in my Dockerfile used to build the image, I’m not able to access the system. I’d like to know how is the best way to set root and/or user passwords in a docker image.