gpt4 book ai didi

apache - Docker 内部 Apache 的权限问题

转载 作者:IT老高 更新时间:2023-10-28 12:45:09 24 4
gpt4 key购买 nike

我正在使用 Docker 来运行 Apache 实例。我的 docker 文件是这样的:

FROM ubuntu

MAINTAINER your.face@gmail.com

RUN cat /etc/passwd
RUN cat /etc/group

RUN apt-get update && apt-get install -yq apache2 php5 libapache2-mod-php5 php5-mysql
RUN apt-get install -yq openssh-server
RUN mkdir /var/run/sshd

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80

ADD config/apache2/000-default.conf /etc/apache2/sites-available/000-default.conf
ADD config/php5/php.ini /etc/php5/apache2/php.ini
ADD config/start.sh /tmp/start.sh
ADD src /var/www

RUN chown -R root:www-data /var/www
RUN chmod u+rwx,g+rx,o+rx /var/www
RUN find /var/www -type d -exec chmod u+rwx,g+rx,o+rx {} +
RUN find /var/www -type f -exec chmod u+rw,g+rw,o+r {} +

#essentially: CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
CMD ["/tmp/start.sh"]

但是,当我构建容器并运行它时,我只会遇到 403 错误。

请注意,我已指定 Apache 应作为 www-data 组中的 www-data 运行,并且/var/www 已递归 chown d 属于 root:www-data

此外,所有目录都是可搜索和可读的,所有文件都是 www-data 组可读和可写的(好吧,根据 ls -la 和 namei -m 它们无论如何都是)。

如何解决这些权限问题?我想不通。

Apache error.log 中的实际错误:

[Fri May 23 18:33:27.663087 2014] [core:error] [pid 14] (13)Permission denied: [client 11.11.11.11:61689] AH00035: access to /index.php denied (filesystem path '/var/www/index.php') because search permissions are missing on a component of the path

编辑:

ls -laR/var/www 在 Dockerfile 末尾的输出:

Step 21 : RUN ls -laR /var/www
---> Running in 74fd3609dfc8
/var/www:
total 1036
drwxr-xr-x 67 root www-data 4096 May 23 18:38 .
drwxr-xr-x 26 root root 4096 May 23 18:38 ..
-rw-rw-r-- 1 root www-data 28 May 23 12:22 .gitignore
-rw-rw-r-- 1 root www-data 501 May 23 12:22 .htaccess
-rw-rw-r-- 1 root www-data 7566 May 23 12:22 index.php

namei -m/var/www/index.php 在 Dockerfile 末尾的输出:

Step 22 : RUN namei -m /var/www/index.php
---> Running in 1203f0353090
f: /var/www/index.php
drwxr-xr-x /
drwxr-xr-x var
drwxr-xr-x www
-rw-rw-r-- index.php

EDIT2

在尝试了一大堆东西之后,包括 chmod -R 777 只是为了看看我是否可以让 anything 工作,我尝试将源文件从将 Dockerfile 放入 /var/www/html,Apache 文件的默认位置。

我完全匹配了默认文件权限(我认为),但它仍然无法正常工作。 Apache 自带的默认 index.html 加载正常,但是添加的 src 文件夹仍然有 403 access denied 错误。

我将 Dockerfile 更改为 ADD src/var/www/html/src 并使用以下方式设置权限:

RUN find /var/www/html -type d -exec chmod u+rwx,g+rx,o+rx {} +
RUN find /var/www/html -type f -exec chmod u+rw,g+r,o+r {} +

运气不好。下面是 /var/wwwls -laR 的一些输出。注意 html 文件夹的权限和 apache2 安装附带的 index.html 的权限与添加的 src文件夹:

Step 19 : RUN ls -laR /var/www/
---> Running in 0520950d0426
/var/www/:
total 12
drwxr-xr-x 6 root root 4096 May 23 19:23 .
drwxr-xr-x 24 root root 4096 May 23 19:23 ..
drwxr-xr-x 5 root root 4096 May 23 19:23 html

/var/www/html:
total 24
drwxr-xr-x 5 root root 4096 May 23 19:23 .
drwxr-xr-x 6 root root 4096 May 23 19:23 ..
-rw-r--r-- 1 root root 11510 May 23 18:28 index.html
drwxr-xr-x 47 root root 4096 May 23 19:23 src

/var/www/html/src:
total 1032
drwxr-xr-x 47 root root 4096 May 23 19:23 .
drwxr-xr-x 5 root root 4096 May 23 19:23 ..
-rw-r--r-- 1 root root 28 May 23 12:22 .gitignore
-rw-r--r-- 1 root root 501 May 23 12:22 .htaccess
-rw-r--r-- 1 root root 7566 May 23 12:22 index.php

也许 chmod 不像我想象的那样工作??

EDIT3

最后一点信息。 Docker 容器由 buildbot 构建,我一直假设它以 root 身份运行。如果不使用 buildbot 进行构建,我无法重现此场景。

通过 sudo docker build -t apache . 在我的笔记本电脑上键入命令构建一切工作正常,但是当 buildbot 执行此操作时会出现问题。不知道为什么:^/

最佳答案

我刚刚在 Running app inside Docker as non-root user 上发布了一个类似的问题后遇到了这个问题。 .

My guess is you can't chmod/ chown files that were added via the ADD command. – thom_nic Jun 19 at 14:14

其实你可以。您只需要在 ADD 之后为将在您的容器内的文件位置发出一个 RUN 命令。例如

ADD extras/dockerstart.sh /usr/local/servicemix/bin/
RUN chmod 755 /usr/local/bin/dockerstart.sh

希望对您有所帮助。它对我有用。

关于apache - Docker 内部 Apache 的权限问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23836416/

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