Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 5962

Dockerfile (docker container) sudo password error

$
0
0

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 ubuntuWORKDIR /appENV PYTHONUNBUFFERED 1ENV PYTHONDONTWRITEBYTECODE 1ENV 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 adminRUN useradd -g sudo -G postgres -p 123 testadminWORKDIR /var/run/RUN chmod 777 postgresql && chown testadmin:postgres postgresqlUSER testadminWORKDIR /appEXPOSE 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 startagain, 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?

  1. I`ve tried to get rid of password completely. Sudo still requires a password for some reason.

Viewing all articles
Browse latest Browse all 5962

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>