gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:45:18 25 4
gpt4 key购买 nike

我在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权限。还是应该安装任何东西?如果需要,我可以根据该图像构建一个新图像。

最佳答案

您只能在构建期间执行此操作,如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用户身份执行任务。

关于docker - 如何在Jenkins docker容器中切换到root?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45229662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com