Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker set user password non-interactively

I would like to set my user vault's password in the Dockerfile and I have tried

RUN echo -e "pass\npass" | passwd "${USER}" 

but get

Enter new UNIX password: Retype new UNIX password: Sorry, passwords do not match
passwd: Authentication token manipulation error
passwd: password unchanged
The command '/bin/sh -c echo -e "pass\npass" | passwd "${USER}"' returned a non-zero code: 10

and am wondering if there's a better way to do this, instead?

like image 810
stdcerr Avatar asked Jun 20 '26 02:06

stdcerr


1 Answers

Instead of using passwd, there is another utility for the: chpasswd. I've resolved this by using the following command in my Dockerfile (after creation of the user):

RUN echo "${USER}:pass" | chpasswd

works like a charm!

like image 95
stdcerr Avatar answered Jun 22 '26 01:06

stdcerr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!