拒绝访问:在添加入口点时(Dockerfile)

huangapple go评论62阅读模式
英文:

Access denied when added entrypoint (dockerfile)

问题

当运行 docker run --rm 9c33 时,我一直收到 /bin/sh: 1: /app/app.sh: 权限被拒绝 的错误消息。我的镜像 ID 是 9c3321cd2fe82768cc953d3e082f26c5583465a864be2d47b4187148088f4e58。

我的 Dockerfile 包含如下内容:

FROM ubuntu
COPY . /app
RUN apt -y update && apt -y install curl
ENTRYPOINT /app/app.sh

在添加 ENTRYPOINT 之前,它正常工作。

我尝试使用 chmod +x 给予特定文件执行权限,但我收到了相同的拒绝访问消息。

运行 ls -la 时,以下是输出:

drwxr-xr-x  3 skyzreal skyzreal 4096 Jun 14 10:39 .
drwxr-xr-x 24 skyzreal skyzreal 4096 Jun 14 10:40 ..
-rw-r--r--  1 skyzreal skyzreal  113 Jun 15 09:50 Dockerfile
-rw-r--r--  1 skyzreal skyzreal   89 Jun 14 10:36 Dockerfile:Zone.Identifier
-rwxr-xr-x  1 skyzreal skyzreal  876 Jun 14 10:36 app.sh
-rw-r--r--  1 skyzreal skyzreal   89 Jun 14 10:36 app.sh:Zone.Identifier
drwxr-xr-x  2 skyzreal skyzreal 4096 Jun 14 10:39 include
-rw-r--r--  1 skyzreal skyzreal  169 Jun 14 10:36 ubuntu.Dockerfile
-rw-r--r--  1 skyzreal skyzreal   89 Jun 14 10:36 ubuntu.Dockerfile:Zone.Identifier

这是我的文件夹的图片,如果有帮助的话。我也是从这个位置运行我的命令

英文:

I just started learning how to create your own dockerfile and image, but I keep getting /bin/sh: 1: /app/app.sh: Permission denied when running docker run --rm 9c33 (my image id is 9c3321cd2fe82768cc953d3e082f26c5583465a864be2d47b4187148088f4e58)

My docker file contains:

FROM ubuntu
COPY . /app
RUN apt -y update && apt -y install curl
ENTRYPOINT /app/app.sh

It worked fine before adding the entrypoint

I tried using chmod +x to give me permission to that specific file, but I receive the same message of denied access
Here is an image of my folders, if it helps. I am running my commands from this location as well

When running ls -la, here is the output

drwxr-xr-x  3 skyzreal skyzreal 4096 Jun 14 10:39 .
drwxr-xr-x 24 skyzreal skyzreal 4096 Jun 14 10:40 ..
-rw-r--r--  1 skyzreal skyzreal  113 Jun 15 09:50 Dockerfile
-rw-r--r--  1 skyzreal skyzreal   89 Jun 14 10:36 Dockerfile:Zone.Identifier
-rwxr-xr-x  1 skyzreal skyzreal  876 Jun 14 10:36 app.sh
-rw-r--r--  1 skyzreal skyzreal   89 Jun 14 10:36 app.sh:Zone.Identifier
drwxr-xr-x  2 skyzreal skyzreal 4096 Jun 14 10:39 include
-rw-r--r--  1 skyzreal skyzreal  169 Jun 14 10:36 ubuntu.Dockerfile
-rw-r--r--  1 skyzreal skyzreal   89 Jun 14 10:36 ubuntu.Dockerfile:Zone.Identifier

答案1

得分: 1

关于文件系统,通常需要设置权限才能读取、写入和/或执行文件。在大多数基于unix的系统中,可以使用chmod命令更改权限。

要授予rwxr-xr-x权限(如果要运行sh文件,则需要此权限),您需要执行以下命令:

chmod 755 /app/app.sh

要通过docker执行此操作,可以使用RUN命令,该命令基本上接受一个字符串数组并将其作为命令执行,每个字符串之间都加入一个空格:

RUN ["chmod", "755", "/app/app.sh"]

这应该解决问题。

此外,大多数基于unix的系统还提供了一种将访问权限授予特定的用户(如root或在OP的情况下skyzreal)的方法。要更改文件的所有权,您需要使用chown命令:

RUN ["chown", "your_user:your_user", "/path/to/file"]

这些命令很简单,但非常重要,因为即使您知道如何使用docker,如果不了解大多数基本的命令行工具和命令,就有可能在某个时候陷入困境。

英文:

When it comes to filesystems, there are usually permissions that one needs to set up in order to be able to read, write and/or execute a file. In most unix based systems, permissions can be changed using the chmod command.

To grant rwxr-xr-x permission (which is required if you want to run a sh file), you'd need to execute the following command:

chmod 755 /app/app.sh

In order to do this via docker, you can use the RUN command which basically takes in an array of strings and executes them as a command, adding a space in between each string:

RUN ["chmod", "755", "/app/app.sh"]

This should solve the issue.

Additionally, most unix based systems also provide a way to grand access to a specific user (as in root or in OP's case skyzreal). To change ownership of a file, you will need to use the chown command:

RUN ["chown", "your_user:your_user", "/path/to/file"]

These commands are quite simple to learn but are very important because even if you know how to use docker, if you don't know about most basic command line tools and commands, you are doomed to get stuck at some point.

huangapple
  • 本文由 发表于 2023年6月15日 21:45:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定