I want the hostname in my Managed CloudRun service to be MyServiceName.RevisionName.InstanceId or anything better than "localhost" which I am getting now. Is this possible ?
-
1What is your goal with a more specific host name? – Grayside Nov 22 '19 at 22:07
-
1Why are you wishing this? – guillaume blaquiere Nov 23 '19 at 19:09
-
Also wondering why you want to do this. The name of the service is what matters. your instances are not servers, they are ephemeral. – Travis Webb Nov 24 '19 at 05:58
-
1I am running an app, that uses the hostname to send data. Whenever the data comes from CloudRun it shows up as "localhost", this is a problem for operations. – RDs Nov 25 '19 at 19:01
-
Hostname is not a meaningful identifier in this context. Is it possible to add additional properties to the data such as a UUID for use in identifying a particular instance? – Grayside Nov 25 '19 at 21:00
-
1) You could use Custom Domain Mapping and assign your instance a real valid DNS name. You can fetch that name from the HTTP request headers. 2) Otherwise, the solution is to not use the hostname. If your goal is a unique name, then how would you handle two instances of Cloud Run? Use the same name or design a unique method of identifying the instance? Either way, the hostname is not a good name source in your use case. Unless you have a clear requirement, use something simple like `cloudrun.local` or add a random number like `33829934.cloudrun.local` if you need instance level uniqueness. – John Hanley Nov 26 '19 at 04:23
2 Answers
Cloud Run is a serverless managed compute platform, meaning that it is precisely built to abstract away all the infrastructure management. The container instances on which Cloud Run services run are ephemeral, meaning that your Cloud Run services will not be mapped to a specific static instance ID. Setting the hostname as you describe on your question will not be possible.
Depending on the nature of the application you can follow one of two possible ways:
Follow one of the suggestions already given on the comments (generate and save an UUID as a variable to the running container's scope so it can serve as an identifier during the container's lifespan). Which I assume would be the best workaround given the simplicity of creating UUIDs. Here are some examples on how to generate UUIDs programatically using Python, JavaScript, and C# given by the Stackoverflow community.
Migrate the container application from Cloud Run services to a Compute Engine VM instance with a custom hostname.

- 3,554
- 2
- 11
- 19
The metadata server provides some attributes to uniquely identify your service instance and correlate it to logs and other information sources.
See cloud run specific attributes and the [metadata server docs](https://cloud.google.com/compute/docs/storing-retrieving-metadata]

- 58,259
- 26
- 121
- 165