[英]How to fix 'Permission denied' in Docker sh entrypoint
I'm trying to create an easy-to-use Docker image for the Garry's Mod server.我正在尝试为 Garry 的 Mod 服务器创建一个易于使用的 Docker 映像。 While my Docker image builds just fine, running it as a container always results in a single error:
/bin/sh: 1: ./easygmod.sh: Permission denied
.虽然我的 Docker 镜像构建得很好,但将它作为容器运行总是会导致一个错误:
/bin/sh: 1: ./easygmod.sh: Permission denied
。
I'm using the cm2network/steamcmd
image as a base.我使用
cm2network/steamcmd
图像作为基础。 I have tried both tags that the aforementioned base image has.我已经尝试了上述基本图像具有的两个标签。 I have tried
chmod +x
, changing users to root
, and fiddling with the shebang in the first line of the easygmod.sh
script, as well as a number of possible typos, particularly in file names and paths.我尝试过
chmod +x
,将用户更改为root
,并在easygmod.sh
脚本的第一行中摆弄shebang,以及一些可能的拼写错误,特别是在文件名和路径中。
I have a GitHub repository for this project which auto-builds to Docker Hub .我有这个项目的GitHub 存储库,它会自动构建到 Docker Hub 。 Currently, the lines of code involving the problematic script are:
目前,涉及有问题脚本的代码行是:
# Start main script
ADD easygmod.sh .
RUN chmod +x easygmod.sh
USER steam
CMD ./easygmod.sh
Also, the shebang/first line of the script is currently #!/bin/sh
.此外,脚本的 shebang/第一行当前是
#!/bin/sh
。
Despite having no logical explanation, the easygmod.sh
script refuses to be executed, always throwing the error Permission denied
.尽管没有合乎逻辑的解释,
easygmod.sh
脚本拒绝执行,总是抛出错误Permission denied
。 This especially confusing given that my only other public GitHub project , which is very similar (similar style Docker image with the same base OS as cm2network/steamcmd
), never had any issues like this.考虑到我唯一的其他公共 GitHub 项目(与
cm2network/steamcmd
具有相同基本操作系统的类似风格的 Docker 映像),这尤其令人困惑,但从未出现过任何此类问题。
The file isn't owned by steam
in the container, so the chmod +x
was insufficient.该文件不归容器中的
steam
所有,因此chmod +x
是不够的。 Either add --chown=steam
to the ADD
, or change your chmod
from +x
to a+rx
.要么将
--chown=steam
添加到ADD
,要么将您的chmod
从+x
更改为a+rx
。
Also, you didn't specify CWD or a path to put those files in. It's likely that the root
version of that image has a CWD that steam
can't access.此外,您没有指定 CWD 或放置这些文件的路径。很可能该映像的
root
版本具有steam
无法访问的 CWD。 You should use /home/steam/
for that instead.你应该使用
/home/steam/
来代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.