2

I'm trying to run an example application in Google Cloud Run (Fully managed). Every time I send a request to the instance, I get a 503 Service unavailable.

The logs tell me, the process is restarted every time on the same PID, so the process is dying with every request.

Since I have a very standard image, i'm not sure if there is a mistake I made or a misunderstanding on how the things are working.

Dockerfile

FROM php:7.4-fpm-alpine3.11

RUN sed -i 's/9000/${PORT}/' /usr/local/etc/php-fpm.d/zz-docker.conf

RUN mkdir /var/www/public; echo 'This page works' > /var/www/public/index.php
EXPOSE ${PORT}
CMD ["php-fpm", "-F", "-R"]

Logs: Cloud Run Logs

Daniel Ocando
  • 3,554
  • 2
  • 11
  • 19
psimms
  • 180
  • 2
  • 9
  • Is your container running locally? Follow [these steps](https://cloud.google.com/run/docs/testing/local#running_locally_using_docker) and let me know if you get the expected output when trying to open `localhost:9090` (step 2) to reach the container. – Daniel Ocando May 26 '20 at 15:01
  • yes, there everything works as expected. I thought it has something to do with the fact that the container has to implement a [http-server](https://cloud.google.com/run/docs/reference/container-contract#port) and php-fpm does not implement such server. But then I switched to a single-container setup with nginx-unit, which implements a http server, and still no success with cloud run. Interestingly the nginx- unit container works, when I am using it as an image for a google compute instance. You can find a question I posted at their github [here](https://github.com/nginx/unit/issues/429) – psimms May 27 '20 at 19:21
  • Yes, you are correct. The container must listen for requests on `0.0.0.0` on the port defined by the `PORT` env variable. Most importantly, the container must [start an HTTP server within 4 minutes after receiving the request and send a request within the time set under the request timeout field](https://cloud.google.com/run/docs/reference/container-contract#startup). Maybe you'd find the following [tutorial](https://dev.to/_mertsimsek/symfony-on-google-cloud-run-pca) useful in order to configure nginx as well as the php-fpm to configure the workers. – Daniel Ocando May 28 '20 at 12:49

2 Answers2

2

Currently I am assuming that the error is due to the missing HTTP Server in the fpm container. I followed the tutorial Daniel provided, which works fine for my current use case.

psimms
  • 180
  • 2
  • 9
0

You need to add web server (ex: nginx, apache) in your dockerfile. Web server will handle your request and transfer to php-fpm if the requested file include php code.

php-fpm & nginx

PHP stack