Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

Forbidden

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

docker ps

And here for docker logs [container-name]

docker logs 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

Dockerfile

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:

path to index.php

like image 352
Will Marcouiller Avatar asked May 24 '18 15:05

Will Marcouiller


People also ask

How do I get root permission in Docker?

As an alternative, we can also access the Docker container as root. In this case, we'll use the nsenter command to access the Docker container. To use the nsenter command, we must know the PID of the running container. This allows us to access the Docker container as a root user and run any command to access any file.

How do you restrict the memory utilization of a container?

To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.


3 Answers

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.

like image 73
Antti A Avatar answered Sep 17 '22 16:09

Antti A


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 :)

like image 27
Mornor Avatar answered Sep 16 '22 16:09

Mornor


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.

like image 34
WISAM Avatar answered Sep 16 '22 16:09

WISAM