I am encountering an issue with my microservice deployment. I am using the FROM php:8.0-fpm-alpine image. During the build process, several dependencies are installed. I set my working directory to /app using WORKDIR /app and copied the code with the following commands:
COPY composer.json composer.lock ./
COPY . .
Then, I run composer install, and at the end, I use CMD [“php-fpm”] to start the PHP-FPM process.
I also have an Nginx container where I have defined routes to the PHP container in a configuration file.
Problem:
When I deploy my container and access my application at a URL like:
http://my-domain/myapi/status
I receive a 502 Bad Gateway error. However, if I execute the following commands:
docker exec -it myapi /bin/sh
php artisan serve –host=0.0.0.0 –port=80 or 9000
And then access the URL:
http://my-domain/myapi/status
The application works fine.
I do not want to run the Laravel development server inside my container. Instead, my Nginx container should directly serve the application content without relying on the Laravel development server.
Could you please advise on how to resolve this issue?
My Dockerfile looks somethink like this
FROM php:8.0-fpm-alpine
RUN apk update && apk add (dependencies)
WORKDIR /app
COPY composer.json composer.lock ./
COPY . .
RUN chown -R www-data:www-data /app/storage /app/bootstrap/cache
&& chmod -R 775 /app/storage /app/bootstrap/cache
RUN composer install
CMD [“php-fpm”]
My application should run without using the development server inside the PHP-Laravel container.
My ultimate goal is to deploy my image to a Kubernetes cluster, where I can use Nginx as a pod with an ALB (Application Load Balancer) or Nginx Ingress for routing.
Daud Ch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.