如何切换到jenkinsdocker集装箱的根?

我有一个docker集装箱内安装Jenkins服务器。 我正在使用的图像是docker pull jenkins 。 之后,我通过docker exec -it b74d035352ec bash连接到容器。 默认的用户是jenkins但我不能切换到根,并得到以下错误:

 jenkins@b74d035352ec:/$ su - su: must be run from a terminal 

运行sudo时出现以下错误:

 $ sudo ls We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. sudo: no tty present and no askpass program specified 

有谁知道如何解决这个问题? 我确实需要该容器的root权限。 或者我应该安装任何东西? 如果需要的话,我可以从这个图像build立一个新的图像。

您只能在生成时间内执行此操作,如文档中所述。

 FROM jenkins # if we want to install via apt USER root RUN apt-get update && apt-get install -y ruby make more-thing-here # drop back to the regular jenkins user - good practice USER jenkins 

所以你必须build立你自己的图像以root用户身份执行任务。