· Updated · 5 min read ·
tutorials google-cloud domain-forwarding redirects

Redirect Domain Using Google Cloud Run

Ekke Uustalu
Ekke Uustalu · Founder
Google Cloud Run domain redirect tutorial

TL;DR: Google Cloud Run can redirect domains using the morbz/docker-web-redirect Docker image. Free tier covers 2M requests/month, but setup requires Docker, Cloud Console, and DNS configuration. For a no-code alternative, Domain-Forward.com handles it in 5 minutes with free HTTPS.


This tutorial shows how to redirect traffic from one domain to another using Google Cloud Run. We’ll use the morbz/docker-web-redirect Docker image, which handles HTTPS domain forwarding redirection via Nginx.

Prerequisites:

Before proceeding with the tutorial, ensure you have:

  1. A Google Cloud account with the necessary permissions to create and manage Google Cloud Run instances.

What is Google Cloud Run?

Google Cloud Run is a fully-managed serverless platform from Google. It runs applications in Docker containers without infrastructure management. The free tier includes 2 million requests per month, which is more than enough for most redirect use cases.

What is morbz/docker-web-redirect?

morbz/docker-web-redirect is a Docker image built specifically for the purpose of redirecting HTTP/S traffic from one domain to another. This Docker image uses Nginx to perform the redirection.

Steps to Redirect the Traffic

(OPTIONAL) Test the Docker Image Locally

Before you can test the image, you need:

  • Docker Desktop
  • A terminal of your choice

If that’s done, pull the Docker image:

docker pull morbz/docker-web-redirect

Test it locally:

docker run -p 8080:80 -e REDIRECT_TARGET="http://example.com" morbz/docker-web-redirect

Visit :8080 in your browser — you should be redirected to http://example.com. Press Ctrl + C to stop the service.

Deploy to Google Cloud Run

Step 1: Creating the service

Create a new Cloud Run service in the Google Cloud Console. Navigate to Cloud Run using the top search.

Cloud run dashboard

Click ‘Create Service’ and configure:

  • Container image URL = morbz/docker-web-redirect
  • Region = closest to your users
  • Autoscaling -> Maximum number of instances = 10

Creating the cloud run service - top configuration

When you scroll down, check Allow unauthenticated invocations. Without this, public traffic can’t reach the service.

Step 2: Creating the service – configure environment variables

Set the REDIRECT_TARGET variable to your destination URL.

Cloud Run environment variables configuration

Understanding Environment Variables

The Docker image uses two environment variables:

  • REDIRECT_TARGET: This is the URL to which the traffic will be redirected.
  • REDIRECT_TYPE: Controls the HTTP status code. Default is 301 (permanent). Set to redirect for 302 (temporary).

Example — permanently redirect to “https://mynewsite.com”:

REDIRECT_TARGET="mynewsite.com"

Step 3: Mapping a custom domain

Once created, the service is accessible via its auto-generated Cloud Run URL.

Cloud Run service created

To redirect your actual domain, navigate back to the Cloud Run service list and click ‘Manage custom domains’.

Cloud Run manage custom domains

Click ‘Add mapping’, select your service, and choose your verified domain.

You may need to verify domain ownership via Google Search Console. Follow this verification tutorial if needed.

Once verified, return to Google Cloud Platform and continue with the domain mapping.

Cloud Run domain mappings

Once the mapping is created, you’ll see the DNS records (A and AAAA) to configure at your registrar.

Cloud Run domain DNS entries

After configuring DNS, you’ll see pending domain mappings in the list. Create a www mapping too so both versions redirect.

Cloud Run domains list

Step 4: Test the Setup

While waiting for DNS propagation, test with the auto-generated Cloud Run URL to confirm the redirect works.

The auto-generated domain redirects correctly:

Cloud run domain redirect test with auto-generated domain

The custom domain also works, with HTTPS automatically provisioned:

Cloud run domain redirect test with custom mapped domain

Conclusion

Your Cloud Run service is now redirecting traffic to the target URL. Once Cloud Run detects the DNS changes (this can take several hours), your custom domain will also redirect correctly.

How Can I Do It Without Docker?

If configuring Docker and Cloud Run is more than you need, Domain-Forward.com handles domain redirects with automatic HTTPS, 301 redirects, and analytics — no containers or cloud configuration needed.

For other approaches, see our guides for AWS Route53 and Google Cloud Functions, or read our overview of all domain redirect options. You can verify your redirect with our redirect tester tool.

Frequently Asked Questions

How do I redirect a domain using Google Cloud Run?
Deploy the morbz/docker-web-redirect Docker image as a Cloud Run service, set the REDIRECT_TARGET environment variable to your destination URL, then map your custom domain through Cloud Run's domain mapping feature.
How much does Google Cloud Run cost for redirects?
Google Cloud Run has a generous free tier of 2 million requests per month. For most domain redirect use cases, you'll stay within the free tier. Beyond that, you pay per request and per CPU/memory second.
Does Google Cloud Run provide HTTPS for redirected domains?
Yes. When you map a custom domain to Cloud Run, it automatically provisions and manages SSL certificates. However, the DNS verification and certificate provisioning can take up to 24 hours.
Is there an easier way to redirect a domain than Google Cloud Run?
Yes. Domain-Forward.com provides domain redirects with automatic HTTPS, 301 redirects, and analytics — no Docker, no cloud configuration needed. Free plan available for up to 5 domains.

Ready to simplify your redirects?

Start forwarding domains in minutes. Free plan available.

Get Started Free