大网数据广告活动
服务器运维问答

chmod: changing permissions of 'myscript.sh' : Operation not permitted

· 52CE 我爱测

While running the following docker file I am getting "chmod: changing permissions of '/scripts/entrypoint.sh': Operation not permitted" error. FROM sonarqube:7.7-community ADD plugins/* /plugins/ ADD scripts/* /scripts/ ADD conf/…

问题原文

原帖链接 · JYOTI PRAKASH MALLICK · CC BY-SA 4.0

While running the following docker file I am getting "chmod: changing permissions of '/scripts/entrypoint.sh': Operation not permitted" error.

FROM sonarqube:7.7-community
ADD plugins/* /plugins/
ADD scripts/* /scripts/
ADD conf/* /conf/
ADD bin/* /bin/
RUN chmod -R a+X /scripts/myScript.sh
ENTRYPOINT ["/scripts/myScript.sh"]

But when I add USER root it is working. But I don't want to run it with root. Any way I can run it without root ?

社区高分解答

原帖链接 · BMitch · CC BY-SA 4.0

Changing permissions of files you do not own in Linux requires root access, and the COPY command is most likely copying the file as root. You can change back to the sonarqube user after fixing the permissions. Here's an example Dockerfile for that:

FROM sonarqube:7.7-community
COPY plugins/ /plugins/
COPY scripts/ /scripts/
COPY conf/ /conf/
COPY bin/ /bin/
USER root
RUN chmod 755 /scripts/myScript.sh
USER sonarqube
ENTRYPOINT ["/scripts/myScript.sh"]

Note I've also switched from ADD to COPY since you are not pulling remote URL's or extracting tar/zip files. The * is also implied when copying a directory. For a single script, you do not need the -R recursive option, and I'm explicit with the permissions since shell scripts also require read access by all users.

If you want the script to be owned by sonarqube instead, you could run:

COPY --chown=sonarqube:sonarqube scripts/ /scripts/

That should allow the user to change permissions on the script without a USER change, but may give that user more access than you desire to modify the script inside the container.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-05-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。