How can I set the root password in a docker container from a script?

Solution 1:

PASSWORD=$(zenity --password --title="Docker" 2>/dev/null)

will open a popup, asking for password, and return it. No password stored in the script

If you have a docker container where you need to set a password, without caring to much about security, you could add a statement in the Dockerfile:

RUN echo "root:root" | chpasswd

Solution 2:

This is not related to Docker. You need to explicitly say passwd that you are going to provide password from stdin.

user='root'
pass='newpassword'
chpasswd <<<"$user:$pass"