So, I’m trying to run a Laravel App inside a Docker Container, so I managed to successfuly build and run the container, but whenever I access it from a web browser it always return 404 Not Found from Nginx.
404 Not Found from Nginx.
So, this is my Dockerfile :
FROM php:8.0-fpm-alpine AS build
RUN apk --no-cache add bash libpng-dev libjpeg-turbo-dev freetype-dev zip git nginx &&
docker-php-ext-configure gd --with-freetype --with-jpeg &&
docker-php-ext-install gd pdo pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php &&
mv composer.phar /usr/local/bin/composer
WORKDIR /var/www
COPY . .
RUN composer install --no-dev --optimize-autoloader
FROM php:8.0-fpm-alpine
RUN apk --no-cache add bash libpng-dev libjpeg-turbo-dev freetype-dev zip git nginx &&
docker-php-ext-configure gd --with-freetype --with-jpeg &&
docker-php-ext-install gd pdo pdo_mysql
WORKDIR /var/www
COPY --from=build /var/www /var/www
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache
EXPOSE 80 9000
CMD ["sh", "-c", "php-fpm & nginx -g 'daemon off;'"]
And this is my default.conf for Nginx :
server {
listen 80;
server_name localhost;
root /var/www/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
I’ve been trying over and over to build and rebuild the container, but still I get the 404 result from Nginx, I really appreciate if there’s any solution available that I can try, Iv’ve been googling and using ChatGPT for days, but still no result, thank you.
I’ve been trying to get rid of Nginx and simply run the Laravel App on port 9000 directly, but I get connection timeout instead.
FROM php:8.0-fpm-alpine AS build
WORKDIR /var/www
RUN apk --no-cache add bash libpng-dev libjpeg-dev libfreetype6-dev zip git &&
docker-php-ext-configure gd --with-freetype --with-jpeg &&
docker-php-ext-install gd pdo pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php &&
mv composer.phar /usr/local/bin/composer
COPY . .
RUN composer install --no-dev --optimize-autoloader
FROM php:8.0-fpm-alpine
WORKDIR /var/www
RUN apk --no-cache add bash libpng-dev libjpeg-dev libfreetype6-dev zip git &&
docker-php-ext-configure gd --with-freetype --with-jpeg &&
docker-php-ext-install gd pdo pdo_mysql
COPY --from=build /var/www /var/www
EXPOSE 9000
CMD ["php-fpm"]