【发布时间】:2014-07-13 05:42:09
【问题描述】:
我正在使用 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 已递归 chownd 属于 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
在 Dockerfile 末尾输出namei -m /var/www/index.php:
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 拒绝访问错误。
我将 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 {} +
没有运气。下面是ls -laR 在/var/www 上的一些输出。请注意,html 文件夹和 index.html 的权限与 apache2 安装的权限匹配添加的 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 执行此操作时会出现问题。不知道为什么:^/
【问题讨论】:
-
我不认为这是一个答案,而是通过 ADD 命令将源添加到 /tmp,然后使用 RUN 命令一次将所有文件复制到 /var/www/html 工作.太奇怪了 ** 10000000!!!!!!1
-
我刚刚在stackoverflow.com/questions/24308760/… 发布了一个类似的问题后遇到了这个问题,我猜你不能chmod/chown 通过
ADD命令添加的文件。 -
请注明docker版本和主机平台以识别。
-
@MarkusOrreilly 如果您将该评论作为答案,我会投票给您!在我拉头发几个小时后,它解决了我的问题。谢谢!
-
同样的问题
标签: apache file-permissions docker