简体   繁体   English

如何在使用 docker 容器时解决 403:Forbidden?

[英]How can I solve 403:Forbidden whilst using a docker container?

I'm new to Docker and currently following this tutorial:我是 Docker 的新手,目前正在关注本教程:

Learn Docker in 12 minutes 12 分钟了解 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]

码头工人日志ae

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:所以你看到文件存在:

index.php 的路径

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.

相关问题 为什么我在 docker 容器中使用 nginx 禁止 403 - Why I got 403 forbidden with nginx in docker container docker 容器中的 laravel 项目,无法访问我的图像 - 403 被禁止 - laravel project in a docker container, cannot access my images - 403 forbidden 禁止 docker 容器 403 的 apache2 反向代理? - apache2 reverse proxy to docker container 403 forbidden? 在docker容器中通过nginx部署应用程序时出现403禁止错误 - 403 Forbidden Error when deploying app through nginx in docker container 从 docker 容器执行时 SpringBoot RestTemplate 返回 403 禁止 - SpringBoot RestTemplate return 403 forbidden when executing from docker container 使用 docker 拉取 aws 深度学习容器时,如何解决出现 Unauthorized Access 401 错误? - How can I solve getting Unauthorized Access 401 error when pulling aws deep learning container with docker? 使用Docker在Django中使用POST数据发出urllib请求时,如何解决Forbidden 403错误? - How to resolve Forbidden 403 error when making a urllib request with POST data in Django using Docker? 我如何开始使用Dockerfile使用Docker容器 - how can i start using docker container using Dockerfile 如何解决docker容器延迟 - How to solve docker container latency Ubuntu Nginx容器403禁止 - Ubuntu nginx container 403 forbidden
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM