草庐IT

apache - Docker 内部 Apache 的权限问题

coder 2023-05-06 原文

我正在使用 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/

有关apache - Docker 内部 Apache 的权限问题的更多相关文章

  1. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

  2. ruby - 通过 rvm 升级 ruby​​gems 的问题 - 2

    尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub

  3. ruby - 通过 RVM (OSX Mountain Lion) 安装 Ruby 2.0.0-p247 时遇到问题 - 2

    我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search

  4. ruby - Fast-stemmer 安装问题 - 2

    由于fast-stemmer的问题,我很难安装我想要的任何ruby​​gem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=

  5. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

  6. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  7. ruby-on-rails - 简单的 Ruby on Rails 问题——如何将评论附加到用户和文章? - 2

    我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。

  8. 叮咚买菜基于 Apache Doris 统一 OLAP 引擎的应用实践 - 2

    导读:随着叮咚买菜业务的发展,不同的业务场景对数据分析提出了不同的需求,他们希望引入一款实时OLAP数据库,构建一个灵活的多维实时查询和分析的平台,统一数据的接入和查询方案,解决各业务线对数据高效实时查询和精细化运营的需求。经过调研选型,最终引入ApacheDoris作为最终的OLAP分析引擎,Doris作为核心的OLAP引擎支持复杂地分析操作、提供多维的数据视图,在叮咚买菜数十个业务场景中广泛应用。作者|叮咚买菜资深数据工程师韩青叮咚买菜创立于2017年5月,是一家专注美好食物的创业公司。叮咚买菜专注吃的事业,为满足更多人“想吃什么”而努力,通过美好食材的供应、美好滋味的开发以及美食品牌的孵

  9. 【高数】用拉格朗日中值定理解决极限问题 - 2

    首先回顾一下拉格朗日定理的内容:函数f(x)是在闭区间[a,b]上连续、开区间(a,b)上可导的函数,那么至少存在一个,使得:通过这个表达式我们可以知道,f(x)是函数的主体,a和b可以看作是主体函数f(x)中所取的两个值。那么可以有,  也就意味着我们可以用来替换 这种替换可以用在求某些多项式差的极限中。方法: 外层函数f(x)是一致的,并且h(x)和g(x)是等价无穷小。此时,利用拉格朗日定理,将原式替换为 ,再进行求解,往往会省去复合函数求极限的很多麻烦。使用要注意:1.要先找到主体函数f(x),即外层函数必须相同。2.f(x)找到后,复合部分是等价无穷小。3.要满足作差的形式。如果是加

  10. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

随机推荐