[英]How can I solve 403:Forbidden whilst using a docker container?
I'm new to Docker and currently following this tutorial:我是 Docker 的新手,目前正在关注本教程:
I created the necessary files and I made it up to display "Hello World!"我创建了必要的文件,并使其显示“Hello World!” on localhost:80.在本地主机上:80。
Beyond that point, I tried to mount the container using the direct reference to my folder so I can update the index.php file to mimic the development evironment, and then I come with this error:除此之外,我尝试使用对我的文件夹的直接引用来挂载容器,以便我可以更新 index.php 文件以模拟开发环境,然后出现此错误:
All I did is change the way the image is ran so I can update the content of the index.php file and see the changes reflect in the webpage when I hit F5.我所做的只是改变图像的运行方式,这样我就可以更新 index.php 文件的内容,并在按 F5 时查看网页中反映的更改。
Currently using Docker for Windows on Windows 10 Pro目前在 Windows 10 Pro 上使用 Docker for Windows
Docker for Windows is running Docker for Windows 正在运行
I followed every steps scrupulously so I don't get myself fooled and it didn't work for me it seems.我一丝不苟地遵循每一步,这样我就不会被愚弄,而且它似乎对我不起作用。
To answer Mornor's question, here is the result for docker ps
为了回答 Mornor 的问题,这里是 docker docker ps
的结果
And here for docker logs [container-name]
这里是docker logs [container-name]
And since I now better understand what happens under the hood, how do I go to solve my problem illustrated in the log?既然我现在更好地了解幕后发生的事情,我该如何解决日志中说明的问题?
Here is my Dockfile
这是我的Dockfile
And the command I executed to run my image:我为运行我的图像而执行的命令:
docker run -p 80:80 -v /wmi/tutorials/docker/src/:/var/www/html/ hello-world
And so you see that the file exists:所以你看到文件存在:
Error is coming from Apache which tries to show you the directory contents as there is no index file available.错误来自 Apache,它试图向您显示目录内容,因为没有可用的索引文件。 Either your docker mapping is not working correctly, or your apache does not have php support installed on it.要么您的 docker 映射工作不正常,要么您的 apache 上没有安装 php 支持。 You are accessing http://localhost , try http://localhost/index.php .您正在访问http://localhost ,请尝试http://localhost/index.php 。
If you get same error, problem is with mapping.如果您遇到相同的错误,则问题出在映射上。 If you get php code the problem is with missing PHP support in Apache.如果您获得 php 代码,则问题在于 Apache 中缺少 PHP 支持。
I think you're wrongly mouting your index.php
.我认为您错误地安装了index.php
。 What you could do to debug it, is to firstly check if the index.php
is indeed mounted within the container.您可以做些什么来调试它,首先检查index.php
是否确实安装在容器中。
You could issue the following command :您可以发出以下命令:
docker run -p 80:80 -v /wmi/tutorials/docker/src/:/var/www/html/ hello-world bash -c 'ls -lsh /var/www/html/'
(use sh
instead of bash
if it does not work). (如果不起作用,请使用sh
而不是bash
)。 If you can indeed see a index.php
, then congratulations your file is correctly mounted, and the error is not coming from Docker, but from Apache.如果您确实可以看到index.php
,那么恭喜您的文件已正确挂载,并且错误不是来自 Docker,而是来自 Apache。
If index.php
is not there, then you have to check your Dockerfile.如果index.php
不存在,那么您必须检查您的 Dockerfile。 You mount src/
, check if /src
is in the same directory as your Dockerfile.您挂载src/
,检查/src
是否与您的 Dockerfile 位于同一目录中。
Keep us updated :)让我们保持更新:)
I know the answer is late but the answer is very easy: this happens When using docker and you have SELinux, be aware that the host has no knowledge of container SELinux policy.我知道答案很晚,但答案很简单:当使用 docker 并且您拥有 SELinux 时,会发生这种情况,请注意主机不了解容器 SELinux 策略。 by adding z通过添加 z
docker run -p 80:80 -v /wmi/tutorials/docker/src/:/var/www/html/:z hello-world
this will automatically do the chcon ....
that you need to do.这将自动执行您需要执行的chcon ....
Check whether the html folder has the proper permission or not.检查html文件夹是否具有适当的权限。 Thank you谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.