1
votes

I am having some issues deploying to Cloud Run lately. When I am trying to deploy the below Dockerfile to Cloud Run, it ends up with the error Failed to start and then listen on the port defined by the PORT environment variable.:

FROM phpmyadmin/phpmyadmin:latest

EXPOSE 8080

RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

ENTRYPOINT [ "/docker-entrypoint.sh" ]

CMD [ "apache2-foreground" ]

The ENTRYPOINT and CMD were added separately even though the phpmyadmin/phpmyadmin:latest uses this same ENTRYPOINT and CMD to see if that would solve it, though it is not required. The same Docker image when deployed using docker run runs properly and listens on port 8080. Is there something I am doing wrong?

This is the command I use to deploy:

gcloud run deploy phpmyadmin --memory=1Gi --platform=managed \
--allow-unauthenticated --add-cloudsql-instances project_id:us-central1:db-name \ 
--region=us-central1 --image gcr.io/project_id/phpmyadmin:1.3 \
--update-env-vars PMA_HOST=localhost,PMA_SOCKET="/cloudsql/project_id:us-central1:db-name",PMA_ABSOLUTE_URI=phpmyadmin.domain.com

This is all I can find in the logs. (Have redacted some data):

https://gist.github.com/shanukk27/9dd4b3076c55307bd6e853a76e7a34e0

1
Can you go to the logging page and share the log details? The message that you have is a standard Cloud Run error message. The problem is: Your containter don't start and thus, Cloud Run detect no port opened on 8080, but the port isn't the problem!!guillaume blaquiere
Didn't share the logs since I couldn't find anything particularly interesting. @guillaumeblaquiere , I have updated the question with the logs.Shanu Koyakutty
Ok, the log simply tell that the healthcheck is KO that's why you have this error. it's "normal". So, what you have a CMD and an ENTRYPOINT in your dockerfile? I never use both, only one of them. I don't know what is ran by Docker Run now! Did you try several different commands?guillaume blaquiere
I just copied the CMD and ENTRYPOINT from the base image phpmyadmin/phpmyadmin:latest . In fact, I don't even require those two as the image will fetch the ENTRYPOINT from the base image. That is what I tried at first, but failed. @guillaumeblaquiereShanu Koyakutty
And what is the content of the /docker-entrypoint.sh file?guillaume blaquiere

1 Answers

4
votes

Cloud Run runtime environment seems to be slightly different than Docker run command. You can't use ENTRYPOINT and CMD in the same time

ENTRYPOINT [ "/docker-entrypoint.sh" ]

CMD [ "apache2-foreground" ]

It works with Docker Run (Why? Docker issue? Docker feature?) and not on Cloud Run (missing feature? bug?).

Use only one of them, for example:

ENTRYPOINT /docker-entrypoint.sh && apache2-foreground

EDIT

A strange remark shared by Shanu is the 2 command works with Wordpress deployment, and doesn't work here.

FROM wordpress:5.3.2-php7.3-apache

EXPOSE 8080

# Copy custom entrypoint from repo
COPY cloud-run-entrypoint.sh /usr/local/bin/

# Change apache listening port and set permission for docker entrypoint
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf && \
chmod +x /usr/local/bin/cloud-run-entrypoint.sh

# Wordpress conf
COPY wordpress/. /var/www/html/

# Custom entrypoint
ENTRYPOINT ["cloud-run-entrypoint.sh","docker-entrypoint.sh"]

# Start apache when docker container starts
CMD ["apache2-foreground"]

The problem is solved here, but the reason is not clear

Note to Googler (Steren? Ahmet?): Can you share more details on this behavior?