John Davidson

php - The requested resource / was not found on this server using only Dockerfile but not with docker-compose.yml

0 comments
Message:


I don't remember what I was trying to test but I always got the following message when I tried to access the root of my server (index.php) : The requested resource / was not found on this server.


So after several attempts, I managed to access it using docker-compose but not with only a Dockerfile.


I'm trying to understand why.


Dockerfile attempt (not working)


|--- Dockerfile
|--- index.php

My Dockerfile :


FROM php:8.1-alpine
COPY . /usr/src/myapp
CMD [ "php", "-S", "0.0.0.0:8000"]

Docker commands :


docker build -t docker_dockerfile_php .
docker run -p 8002:8000 docker_dockerfile_php

Now when I try to access localhost:8002, I have the following message : The requested resource / was not found on this server.


Docker compose attempt (working)


|--- docker
|--- php
|--- Dockerfile
|--- docker-compose.yml
|--- index.php

My Dockerfile :


FROM php:8.1-alpine
WORKDIR /usr/src/myapp
CMD [ "php", "-S", "0.0.0.0:8000"]

My docker-compose.yml :


services:
php:
image: docker_compose_php
build: ./docker/php
ports:
- 8001:8000
volumes:
- ./:/usr/src/myapp

Docker commands :


docker-compose build
docker-compose up

Now when I try to access localhost:8001, I can acces my index.php file.


With the Docker compose attempt, I can use Xdebug on VSC with .devcontainer.


If anyone can enlighten me, I would be grateful.



My Answer:
"php", "-S", "0.0.0.0:80", "-t", "/usr/src/myapp" ]_

With this Dockerfile, I was not able to access the root of my server. I kept getting the "The requested resource / was not found on this server" message.

However, when I used a docker-compose.yml file with the following content, I was able to access the root of my server without any issues:

yaml
version: '3'
services:
web:
build: .
ports:
- "8080:80"


I ran `docker-compose up` and was able to access my server at `http://localhost:8080`.

I'm not sure why the Dockerfile alone did not work for me, but using docker-compose seemed to solve the issue.

Rate this post

4 of 5 based on 4743 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us