Google Cloud Run is new. Is it possible to run WordPress docker on it? Perhaps using gce as database for the mysql/mariadb. Can't find any discussion on this
1 Answers
Although I think this is possible, it's not a good use of your time to go through this exercise. Cloud Run might not be the right tool for the job.
UPDATE someone blogged a tutorial about this (use at your own risk): https://medium.com/acadevmy/how-to-install-a-wordpress-site-on-google-cloud-run-828bdc0d0e96
Here are a few points to consider;
(UPDATE: this is not true anymore) Currently Cloud Run doesn't support natively connecting to Cloud SQL (mysql). There's been some hacks like spinning up a cloudsql_proxy inside the container: How to securely connect to Cloud SQL from Cloud Run? which could work OK.
You need to prepare your
wp-config.php
beforehand and bake it into your container image. Since your container will be wiped away every now and then, you should install your blog (creates awp-config.php
) and bake the resulting file into the container image, so that when the container restarts, it doesn't lose your wp-config.php.Persistent storage might be a problem: Similar to point #2, restarting a container will delete the files saved to the container after it started. You need to make sure stuff like installed plugins, image uploads etc SHOULD NOT write to the local filesystem of the container. (I'm not sure if wordpress lets you write such files to other places like GCS/S3 buckets.) To achieve this, you'd probably end up using something like the https://wordpress.org/plugins/wp-stateless/ plugin or gcs-media-plugin.
Any file written to local filesystem of a Cloud Run container also count towards your container's available memory, so your application may run out of memory if you keep writing files to it.
Long story short, if you can make sure your WP installation doesn't write/modify files on your local disk, it should be working fine.
I think Cloud Run might be the wrong tool for the job here since it runs "stateless" containers, and it's pretty damn hard to make WordPress stateless, especially if you're installing themes/plugins, configuring things etc. Not to mention, your Cloud SQL server won't be "serverless", and you'll be paying for it while it's not getting any requests as well.
(P.S. This would be a good exercise to try out and write a blog post about! If you do that, add it to the awesome-cloudrun repo.)

- 1
- 1

- 42,679
- 38
- 138
- 214
-
2I have created a Cloud Run WordPress setup. I plan to document this on my website in the next few days. I am also writing some articles on Cloud Run security. WordPress on CloudRun works pretty well. Cold starts are not bad (2000 ms) and page response for warm instances are nearly instant. Setup is not much different than an autoscaled WordPress system. – John Hanley May 01 '19 at 19:44
-
@JohnHanley, I'd love to hear more about how you run WordPress on Cloud Run! Is there a writeup? – Martin Omander Jul 24 '19 at 08:11
-
Alternative: https://medium.com/acadevmy/how-to-install-a-wordpress-site-on-google-cloud-run-828bdc0d0e96 – ahmet alp balkan Jul 24 '19 at 15:07
-
@MartinOmander - I did not write the WordPress article. I did leave my CloudRun/WordPress site running until last weekend and I experienced no problems during that 2.5 months. The site was mapped to a custom domain publically available. – John Hanley Jul 24 '19 at 17:19
-
2@MartinOmander - One of the reasons that I did not write the article is that I decided to not recommend Cloud Run for WordPress. In a real-world WordPress site, you are constantly updating the installation with patches and updates. I still think WordPress works best the old fashioned way: Cloud SQL + Load Balancer + CDN + GCE. WordPress does not fit well into an automated pipeline for patches and updates. – John Hanley Jul 24 '19 at 18:00
-
@JohnHanley that makes perfect sense. Thanks for your insight! – Martin Omander Aug 12 '19 at 22:40
-
@MartinOmander I wonder if one could use a system that automatically pushes theme/plugin modifications to git, combined with a CI/CD step that then rebuilds and redploys the image which Cloud Run uses. For the first part of that, see https://www.presslabs.com/docs/code/gitfs/ or https://github.com/presslabs/gitium – Peter W Apr 14 '21 at 04:39
-
if you're use to a git workflow, you can run wordpress using composer for php. this is how we run a couple of wordpress sites. Git + php composer + docker containers. Its a lot to learn for a regular wordpress admin. I'd imagine experience as php developer would be a requirement to try this setup. The benefits? having matching environments, dev, test, production - and sharing the first 2 with other devs if needed. Like a theme or plugin developer. – aibarra Jun 24 '21 at 22:39