Subject: [alpine-user] Docker add user pwd

From: Gabor Toth <[email-masked]>
Date: Mon, 9 Apr 2018 10:09:57 +0200

Dear All,

I am trying to add a user, and then set a password for the user in a
Dockerfile using node:8-alpine as base image, I am running the following
command, but when I run the container, the user has no password at the end:

#Add user

RUN ["adduser","-D","-s","/bin/bash", "admin"]
#Set pwd for user

#this is not working
RUN ["echo","admin:password","|", "chpasswd"]

So I am wondering what the best practice here. Thanks,

Gabor

---

From: Achim <[email-masked]>
Date: Mon, 9 Apr 2018 19:34:18 +0200

> RUN ["echo","admin:password","|", "chpasswd"]

try with /bin/echo

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Gabor Toth <[email-masked]>
Date: Mon, 9 Apr 2018 23:23:23 +0200

Thanks, resolved:RUN ["/bin/bash","-c","echo user:somepassword | chpasswd"]

---

From: Cág <[email-masked]>
Date: Mon, 9 Apr 2018 14:39:13 +0000

> RUN ["echo","admin:password","|", "chpasswd"]

I am not an expert and have never used it, but the docs[0] show, that
you should just "RUN adduser -D -s /bin/bash admin" and
"RUN echo admin:password | chpasswd", i.e. no hard brackets.

[0]: https://docs.docker.com/engine/reference/builder/

--
caóc

---

---

From: Rainer Gerhards <[email-masked]>
Date: Mon, 09 Apr 2018 14:47:37 +0000

The exec form of RUN does not invoke a shell itself, so neither the pipe
works nor the echo command. You need to add the sh as first parameters -
example (with bash) is in the quoted doc.

HTH
Rainer

Sent from phone, thus brief.