如何在Jenkins docker容器中切换到root?

时间:2017-07-21 05:30:29

标签: docker jenkins

我在Docker容器中设置了Jenkins服务器。我使用的图片是docker pull jenkins。之后,我通过docker exec -it b74d035352ec bash连接到容器。默认用户为jenkins,但我无法切换到root并获得以下错误:

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权限。或者我应该安装什么?如果需要,我可以根据此图像构建新图像。

1 个答案:

答案 0 :(得分:6)

您只能在构建期间执行此操作,如documentation

中所述
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

因此,您必须构建自己的映像,以 root 用户身份执行任务。

相关问题