dockerauthenticationdockerfilepasswd

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?


Solution

  • 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!