Assign a Custom Domain to a Google Cloud Run Service

Learn how to assign a custom domain to your Google Cloud Run Service for a professional and branded URL.
Domain Names
GCP
Free-Tier
Author

Juan C. Rodriguez

Published

November 20, 2024

Keywords

Shiny, GCP, Cloud Run, Docker, Free Tier, Domain Names

Assign a Custom Domain to a Google Cloud Run Service

In this post, we’ll guide you through assigning a custom domain to a Google Cloud Run Service, such as the one we deployed in our previous post. Using Google Cloud Run’s Domain Mappings feature, we’ll map your Shiny app to a memorable domain name like “everysinglecountry.com”.

Prerequisites

Before we begin, ensure that:

  • Your Shiny app is deployed in one of the supported regions for Domain Mappings.
  • You have already purchased a domain. For this example, we bought “everysinglecountry.com” at Porkbun for $11.06/year. You can use any registrar as the steps are similar.

Let’s get started!


On Google Cloud Platform (GCP)

  1. Log in to the Google Cloud console and open the Navigation menu (three horizontal lines icon).

Click the 'Navigation menu' icon.

  1. Select “Cloud Run”.

Click 'Cloud Run'.

  1. Click “MANAGE CUSTOM DOMAINS”.

Click 'MANAGE CUSTOM DOMAINS'.

  1. Click “ADD MAPPING”.

Click 'ADD MAPPING'.

  1. Select your service, such as “everysinglecountry”.

Select the desired service.

  1. Click “Cloud Run Domain Mappings”.

Click 'Cloud Run Domain Mappings'.

  1. Enter your domain name (e.g., “everysinglecountry.com”) and click “CONTINUE”.

Enter your domain to verify.

  1. Click “VERIFY IN SEARCH CONSOLE” to validate ownership.

Click 'VERIFY IN SEARCH CONSOLE'.

  1. Enter the domain name in the “Domain” panel, and click “CONTINUE”.

Enter the domain name, and click 'CONTINUE'.

  1. Ensure the selected record type is “TXT”, then copy the TXT record (“google-site-verification=…”).

Copy the TXT record.

On Your Domain Registrar (Porkbun in This Example)

  1. Keep the GCP tab open. Open Porkbun and click “DNS” for your domain (e.g., “everysinglecountry.com”).

Click 'DNS' in Porkbun's domain to verify.

  1. Add a “TXT” record by pasting the value from Step 10 into the “Answer” field, then click “Add”.

Paste the 'TXT', and click 'Add'.

  1. Keep the Porkbun tab open. Return to the GCP tab and click “VERIFY”.

Click 'VERIFY' in the GCP panel.

  1. Once ownership is confirmed, you’ll see the message “Ownership verified”.

Wait for the 'Ownership verified' message to appear.

  1. Click “REFRESH”.

Click 'REFRESH'.

16.Click “CONTINUE”.

Click 'CONTINUE'.

Adding DNS Records.

  1. In the GCP tab, you’ll see the required DNS records listed. Copy each record one by one (starting with the “A” records).

Copy the first DNS record.

  1. Switch to the Porkbun tab. Before adding the new DNS records, remove any existing “ALIAS” and “CNAME” records by clicking the trashcan icon to the right of each entry.

Delete the 'ALIAS' and 'CNAME' DNS records.

  1. Add the “A” records. For each record, select “A” as the “Type”, enter the corresponding IP address into the “Answer” field, and click “Add”.

Copy each of the DNS records in Porkbun.

  1. Next, add the “AAAA” records. Follow the same process, selecting “AAAA” as the “Type” and pasting the corresponding values from the GCP tab into the “Answer” field.

Copy each of the DNS records in Porkbun.

  1. In this example, there are a total of 8 DNS records to add. After adding all the DNS records in Porkbun, your configuration should look similar to this:

Resulting DNS records in Porkbun.

  1. Go back to the GCP tab and click “DONE” to close the DNS records list. Now, you’ll need to wait for DNS propagation. This process can take a few minutes to several hours, depending on your domain registrar and internet service provider. In this example, it took one hour, but it can be shorter or longer.

Wait for DNS propagation.

  1. Once the DNS propagation is complete, you’ll see a green checkmark next to your domain in the GCP Domain Mapping panel. This indicates that your custom domain is successfully linked to your Cloud Run service.

All done! Your Shiny app is now live on your custom domain.


Congratulations! Your Shiny app is now accessible at its new custom domain, providing a professional and branded experience for your users.

Enjoy your new setup!