Caddy works with Google Cloud Run

Caddy is great, but server setup is painful.
So, let’s use Google Cloud Run. You can use Caddy in minutes.
With Always Free, you can try it with little concern for billing.


Contracted Google Cloud Platform and completed Google Cloud Run official documentation “Quickstart: Build and Deploy”:

Caddy + PHP

This replaces php:apache.
Put the files to be installed in root together with Dockerfile.

Build: (or docker)

gcloud builds submit --tag

Deploy: (or GCP console)

gcloud run deploy --image --platform managed

スクリーンショット 2020-01-26 10.09.52

Note: See 502 Bad Gateway immediately after deployment. At that time php-fpm is still booting.

Freely editable Caddyfile

Display today’s date using a template.

gcloud builds submit --tag
gcloud run deploy --image --platform managed

スクリーンショット 2020-01-26 10.45.28


  • This Caddy is v1. v1 and v2 have a difference in the syntax of Caddyfile.
  • Do not change after Caddyfile:{$PORT} and tls off
    This (IP address:port and custom domain) is realized on Cloud Run side.



If you fail to build, try:

gcloud builds submit --project PROJECT-ID --tag

I also tried the official Docker image for Caddy v2.

For now, editing Caddyfile required root privileges.

gcloud builds submit --project PROJECT-ID --tag
gcloud run deploy --image --platform managed

Free Caddyfile:


Thanks for the guide! This is really interesting. Maybe we should provide some sort of official image or container or something for GCR?

This topic was automatically closed after 180 days. New replies are no longer allowed.