简体   繁体   中英

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

I'm new to Docker and currently following this tutorial:

Learn Docker in 12 minutes

I created the necessary files and I made it up to display "Hello World!" on localhost: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:

禁止的

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.

Currently using Docker for Windows on Windows 10 Pro

Docker for Windows is running

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

码头工人

And here for 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

文件

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. Either your docker mapping is not working correctly, or your apache does not have php support installed on it. You are accessing http://localhost , try 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.

I think you're wrongly mouting your index.php . What you could do to debug it, is to firstly check if the index.php is indeed mounted within the container.
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). 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.

If index.php is not there, then you have to check your Dockerfile. You mount src/ , check if /src is in the same directory as your 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. by adding 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.

Check whether the html folder has the proper permission or not. Thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM