热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

apache在docker内部的权限问题-permissionissueswithapacheinsidedocker

Imusingdockertorunanapacheinstance.Mydockerfilegoessomethinglikethis:我正在使用docker来运行一

I'm using docker to run an apache instance. My docker file goes something like this:

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

However, when I build the container and run it, I only ever get 403 errors.

然而,当我构建容器并运行它时,我只会得到403个错误。

Notice that I've specified that apache should run as www-data in www-data group, and that /var/www has been recursively chownd to belong to root:www-data.

请注意,我已经指定apache应该作为www-data组中的www-data运行,并且/var/www已经被递归地分配到属于根:www-data的chownd中。

Also, all directories are searchable and readable, and all files are readable and writeable by the www-data group (well, according to ls -la and namei -m they are anyways).

此外,所有目录都是可搜索和可读的,所有文件都是可读和可写的。

How do I fix these permissions issues? I cant figure it out.

如何修复这些权限问题?我搞不懂。

Actual error from apache error.log:

来自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

EDIT:

编辑:

output of ls -laR /var/www at the end of the Dockerfile:

l -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

output of namei -m /var/www/index.php at the end of the Dockerfile:

namei -m /var/www/index的输出。在Dockerfile末尾的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

EDIT2

After trying a whole bunch of things, including chmod -R 777 just to see if I could get anything to work, I tried putting the source files added from the Dockerfile into /var/www/html, the default location for apache files to be served.

在尝试了一大堆东西(包括chmod - r777)之后,我试着把从Dockerfile中添加的源文件添加到/var/www/html中,这是apache文件的默认位置。

I matched the default file permissions exactly (I think), and it still isn't working. The default index.html that comes with apache loads just fine, but the added src folder still have a 403 access denied error.

我完全匹配了默认的文件权限(我认为),但它仍然不能工作。默认的索引。apache附带的html加载很好,但是添加的src文件夹仍然有一个403访问拒绝错误。

I changed the Dockerfile to ADD src /var/www/html/src and the permissions were set using:

我更改了Dockerfile以添加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 {} +

No luck. Below is some of the output of ls -laR on /var/www. Notice that the permissions for the html folder and index.html that come with an apache2 install match those of the added src folder:

没有运气。下面是ls -laR在/var/www上的一些输出注意html文件夹和索引的权限。带有apache2安装的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

Perhaps chmod doesn't work quite the way I thought it does??

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

EDIT3

EDIT3

A final bit of information. The Docker container is being built by buildbot, which I've been assuming runs as root. I haven't been able to reproduce this scenario without using buildbot to do the building.

最后一点信息。Docker容器是由buildbot构建的,我一直假设它作为根运行。我还没有使用buildbot来复制这个场景。

Building everything via sudo docker build -t apache . type commands on my laptop works fine, but the problems arise when buildbot does it. No idea why :^/

通过sudo docker build -t apache构建所有内容。在我的笔记本电脑上键入命令很好,但是当buildbot完成时,问题就出现了。不知道为什么:^ /

2 个解决方案

#1


8  

I just ran into this after posting a similar question at Running app inside Docker as non-root user.

在Docker内部运行app时,我也遇到过类似的问题。

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

我的猜测是您不能通过ADD命令添加chmod/ chown文件。-托马斯尼克19日14点

Actually you can. You just need to issue a a RUN command after the ADD for the file location that will be INSIDE your container. For example

实际上你可以。您只需要在添加文件位置之后发出一个RUN命令,该文件位置将位于您的容器内。例如

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

Hope that helps. It worked for me.

希望有帮助。它为我工作。

#2


2  

I encountered a similar issue; however my container was using VOLUME to map directories across the container.

我遇到过类似的问题;然而,我的容器使用体积来映射容器中的目录。

Changing the permissions on the directory that maps to /var/www/html itself remedied the 403 Forbidden errors.

更改映射到/var/www/html的目录的权限,可以纠正403个禁止的错误。

docker-host$ ls -ld /var/www/html
drwxr--r--  53 me  staff  1802 Mar  8 22:33 .

docker-host$ chmod a+x /var/www/html

docker-host$ ls -ld /var/www/html
drwxr-xr-x  53 me  staff  1802 Mar  8 22:33 .

Note that chmod must be applied on the Docker host, not within the container. Executing it within the container effects no change to the directory.

注意,必须将chmod应用于Docker主机,而不是容器内。在容器中执行它不会对目录产生任何更改。

docker-container$ chmod a+x /var/www/html

docker-container$ ls -ld /var/www/html
drwxr--r--  53 me  staff  1802 Mar  8 22:33 .

推荐阅读
  • 使用圣杯布局模式实现网站首页的内容布局
    本文介绍了使用圣杯布局模式实现网站首页的内容布局的方法,包括HTML部分代码和实例。同时还提供了公司新闻、最新产品、关于我们、联系我们等页面的布局示例。商品展示区包括了车里子和农家生态土鸡蛋等产品的价格信息。 ... [详细]
  • 本文介绍了在Ubuntu下制作deb安装包及离线安装包的方法,通过备份/var/cache/apt/archives文件夹中的安装包,并建立包列表及依赖信息文件,添加本地源,更新源列表,可以在没有网络的情况下更新系统。同时提供了命令示例和资源下载链接。 ... [详细]
  • 在Kubernetes上部署JupyterHub的步骤和实验依赖
    本文介绍了在Kubernetes上部署JupyterHub的步骤和实验所需的依赖,包括安装Docker和K8s,使用kubeadm进行安装,以及更新下载的镜像等。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 解决VS写C#项目导入MySQL数据源报错“You have a usable connection already”问题的正确方法
    本文介绍了在VS写C#项目导入MySQL数据源时出现报错“You have a usable connection already”的问题,并给出了正确的解决方法。详细描述了问题的出现情况和报错信息,并提供了解决该问题的步骤和注意事项。 ... [详细]
  • PHPMailer邮件类邮件发送功能的使用教学及注意事项
    本文介绍了使用国外开源码PHPMailer邮件类实现邮件发送功能的简单教学,同时提供了一些注意事项。文章涵盖了字符集设置、发送HTML格式邮件、群发邮件以及避免类的重定义等方面的内容。此外,还提供了一些与PHP相关的资源和服务,如传奇手游游戏源码下载、vscode字体调整、数据恢复、Ubuntu实验环境搭建、北京爬虫市场、进阶PHP和SEO人员需注意的内容。 ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • CentOS 6.5安装VMware Tools及共享文件夹显示问题解决方法
    本文介绍了在CentOS 6.5上安装VMware Tools及解决共享文件夹显示问题的方法。包括清空CD/DVD使用的ISO镜像文件、创建挂载目录、改变光驱设备的读写权限等步骤。最后给出了拷贝解压VMware Tools的操作。 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • 本文介绍了GregorianCalendar类的基本信息,包括它是Calendar的子类,提供了世界上大多数国家使用的标准日历系统。默认情况下,它对应格里高利日历创立时的日期,但可以通过调用setGregorianChange()方法来更改起始日期。同时,文中还提到了GregorianCalendar类为每个日历字段使用的默认值。 ... [详细]
  • 本文介绍了MVP架构模式及其在国庆技术博客中的应用。MVP架构模式是一种演变自MVC架构的新模式,其中View和Model之间的通信通过Presenter进行。相比MVC架构,MVP架构将交互逻辑放在Presenter内部,而View直接从Model中读取数据而不是通过Controller。本文还探讨了MVP架构在国庆技术博客中的具体应用。 ... [详细]
author-avatar
陈可1993_532
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有