I faced some troubles dealing with sudo inside docker container.
First of all: my goal is to execute several commands at the start of docker container (CMD line) which requires root privileges. There is no problem when you execute them under default root container user. But I want to create the different user with root privileges and execute same commands using him.
Here is my dockerfile
FROM ubuntu
WORKDIR /app
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get -y install postgresql python3-pip
#installing sudo
RUN apt-get install sudo
COPY requirements.txt .
COPY . .
#creating admin
RUN useradd -g sudo -G postgres -p 123 testadmin
WORKDIR /var/run/
RUN chmod 777 postgresql && chown testadmin:postgres postgresql
USER testadmin
WORKDIR /app
EXPOSE 8000
#CMD sh /app/entrypoint.sh
Container successfully builds up. I have superuser "testadmin" selected with password "123".
Then I`m entering container cli and trying to execute folowing command:
sudo service postgresql start again, it requires root previleges
System asks for password. When I type "123" and enter it says "Sorry, try again".
I have no idea why it`s happening.
I`m new to docker and linux and I understand that my containers build approach is bad. Im doing this for educational purposes. Im looking for solution only using DOCKEFILE and not docker-compose even though it`s easier. May you please help me to create user with root privileges and execute all of my commands using him?
- I`ve tried to get rid of password completely. Sudo still requires a password for some reason.