如何编写docker脚本,以便sudo在Docker用户中工作?
问题描述:
我已经跑了Ubuntu的空泊坞窗容器并创建了一个用户sudo
这样:如何编写docker脚本,以便sudo在Docker用户中工作?
[email protected]$ docker run -it ubuntu bash
[email protected]:/# apt-get update
[email protected]:/# apt-get -y install sudo
[email protected]:/# useradd -m -p mosesdocker -s /bin/bash ubiwan
[email protected]:/# usermod -aG sudo ubiwan # add user to sudo list
[email protected]:/# su - ubiwan # login to the ubiwan user
当我登录的ubiwan
,密码似乎并没有被mosesdocker
由useradd -m -p mosesdocker -s /bin/bash ubiwan
规定。我输入了正确的密码,但我得到:
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
[email protected]:~$ sudo su
[sudo] password for ubiwan:
Sorry, try again.
[sudo] password for ubiwan:
Sorry, try again.
[sudo] password for ubiwan:
sudo: 3 incorrect password attempts
这是为什么?
是否可以在Docker中使用sudo
?什么是“建议”在Docker中执行sudo
操作?
如何编写docker脚本以便sudo在Docker用户中工作?
答
您需要使用passwd将用户的密码设置为root。
如果您以ubiwan身份登录,首先输入exit。 然后,当根型:
passwd ubiwan
给该用户的密码。 然后,您可以使用sudo作为具有此密码的ubiwan用户
Stack Overflow是编程和开发问题的网站。这个问题似乎与题目无关,因为它不涉及编程或开发。请参阅帮助中心的[我可以询问哪些主题](http://stackoverflow.com/help/on-topic)。也许[请求Ubuntu](http://askubuntu.com/)或[Unix&Linux Stack Exchange](http://unix.stackexchange.com/)会是一个更好的地方。另请参阅[我在哪里发布有关Dev Ops的问题?](http://meta.stackexchange.com/q/134306) – jww