ENV USERNAME ros
RUN adduser --ingroup sudo --disabled-password --gecos "" --shell /bin/bash --home /home/$USERNAME $USERNAME
RUN bash -c 'echo $USERNAME:ros | chpasswd'
ENV HOME /home/$USERNAME
My goal is to have an account with sudo privileges.
The context is that I am trying to create a Docker image with a working installation of ROS. The ROS installation is complicated and includes running many commands and scripts. I know the above statement is probably wrong because it is creating files with owner ros
and group sudo
.
Although I agree with the comments saying that in the majority of cases you avoid sudo in Docker, I also had the same situation where I needed to have a non-root user with passwordless sudo privileges inside Docker.
This is my Dockerfile that defines a sudo user
This is the relevant part from it:
Hope this helps.