Skip to content
Advertisement

How to write the docker script such that sudo works in Docker user? [closed]

I’ve ran an empty Docker container with Ubuntu and created a sudo user as such:

JavaScript

And when I logged in as ubiwan, the password doesn’t seem to be mosesdocker as specified by useradd -m -p mosesdocker -s /bin/bash ubiwan. I’ve typed the correct password but I get:

JavaScript

Why is that so?

Is it possible to use sudo in Docker? What is the “suggested” to perform sudo actions in Docker?

How to write the docker script such that sudo works in Docker user?

Advertisement

Answer

You need to set the password for the user as root using passwd.

First of all type exit if you are logged in as ubiwan. Then as root type:

JavaScript

Give a password for this user. Then you can use sudo as the ubiwan user with this password

Advertisement