I am trying to change a password for a user I am creating during the run of a dockerfile:
RUN groupadd --system ${UNAME} --gid ${UID} && \
useradd --uid ${UID} --system --gid ${UNAME} --home-dir /home/${UNAME} --create-home --comment "Docker image user" ${UNAME} && \
chown -R ${UNAME}:${UNAME} /home/${UNAME} && \
usermod -aG sudo ${UNAME}
RUN echo '${UNAME}:password' | chpasswd
The second RUN
command fails with
Authentication token manipulation error chpasswd: (line 1, user ${UNAME}) password not changed ```
Doing the very same like so, does work:
RUN useradd pi && \
mkdir -p /home/pi && \
chown pi /home/pi && \
echo 'pi:password' | chpasswd
I don't understand the difference. I just want to give ${UNAME} a constant password password
.
working for me now:
use a single RUN
command for less docker images.
RUN groupadd --system ${UNAME} --gid ${UID}
RUN useradd --uid ${UID} --system --gid ${UNAME} --home-dir /home/${UNAME} --create-home --comment "Docker image user" ${UNAME}
RUN chown -R ${UNAME}:${UNAME} /home/${UNAME}
RUN usermod -aG sudo ${UNAME}
RUN echo "${UNAME} ALL=(ALL) ALL" | sudo tee /etc/sudoers.d/permissions
RUN echo ${UNAME}:password | chpasswd
Notice the added line RUN echo "${UNAME} ALL=(ALL) ALL" | sudo tee /etc/sudoers.d/permissions