gpt4 book ai didi

docker - 如何更改 Dockerfile 中文件的权限?

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

我有以下 Dockerfile:

FROM sonarqube

ADD https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/
RUN chmod +r /opt/sonarqube/extensions/plugins/ && chown -R sonarqube.sonarqube /opt/sonarqube/extensions/plugins/

我收到以下错误:

Step 3/3 : RUN chmod +x /opt/sonarqube/extensions/plugins/ && chown -R sonarqube.sonarqube /opt/sonarqube/extensions/plugins/
---> Running in 0fd0abc88b73
chown: changing ownership of '/opt/sonarqube/extensions/plugins/sonar-gitlab-plugin-4.0.0.jar': Operation not permitted
The command '/bin/sh -c chmod +x /opt/sonarqube/extensions/plugins/ && chown -R sonarqube.sonarqube /opt/sonarqube/extensions/plugins/' returned a non-zero code: 1

如果我这样做:

FROM sonarqube


ADD https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/
RUN sudo chmod +r /opt/sonarqube/extensions/plugins/ && sudo chown -R sonarqube.sonarqube /opt/sonarqube/extensions/plugins/

我收到以下错误:

Step 3/3 : RUN sudo chmod +x /opt/sonarqube/extensions/plugins/ && sudo chown -R sonarqube.sonarqube /opt/sonarqube/extensions/plugins/
---> Running in c7dc030ea2ac
/bin/sh: 1: sudo: not found
The command '/bin/sh -c sudo chmod +x /opt/sonarqube/extensions/plugins/ && sudo chown -R sonarqube.sonarqube /opt/sonarqube/extensions/plugins/' returned a non-zero code: 127

如何在 Dockerfile 中更改文件的权限?

最佳答案

chmod +r/opt/sonarqube/extensions/plugins/ 会抛出错误,因为 sonarqube 容器是以用户 sonarqube 运行的(参见 USER sonarqube Dockerfile 中的命令:https://github.com/SonarSource/docker-sonarqube/blob/master/7.7-community/Dockerfile )

sudo 未安装在镜像中,因此您将无法使用 sudo 运行命令。相反,正如 M. Alekseev 提到的,将用户更改为 root 并运行您的自定义命令。

USER root
RUN ...
RUN ...

# switch back to user sonarqube for security
USER sonarqube

我建议在安装自定义包等后切换回用户 sonarqube

请注意,您可能需要为 root 用户创建的文件设置权限。

关于docker - 如何更改 Dockerfile 中文件的权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56040125/

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