Fetch container ID in Cloud Run Job or service

ns2
Bronze 3
Bronze 3

Hi,

I have a specific use case to fetch container ID for a container deployed as a Service/Job in Cloud Run.
The deployment uses second generation execution environment.

The container ID doesn't appear to be present at 

 

/proc/<pid>/cgroup

 


1.  Can we fetch the container ID for Cloud Run Jobs/Service.
2. What is the container runtime used in Cloud Run 
    Is it docker or containerd or something else.

 

1 7 258
7 REPLIES 7

1. to fetch the container id gcloud run jobs list will give you the running job ids  gcloud run jobs describe {id} will provide container id or gcloud run services list and gcloud run services describe {id} if it is a service and not a job - you can pipe the 1st command to jq and parse the ids to the 2nd cmd and pipe its output to jq for the container id field.

2. something else (OCI - open container runtime) but OCI supports docker, containerd, and  knative Container runtime contract  |  Cloud Run Documentation  |  Google Cloud

ns2
Bronze 3
Bronze 3

Thanks @djs_75 for quick response.

I tried running gcloud run jobs list and gcloud run jobs describe {id}. But couldn't find the container Id in the output.

 

✔ Job centos in region us-central1
Executed 1 time
Last executed 2024-02-15T07:14:16.492171Z with execution centos-vdn9s
Last updated on 2024-02-15T07:14:15.894446Z by #####
 
Image:           ###
Tasks:           1
Memory:          512Mi
CPU:             1000m
Task Timeout:    10m
Max Retries:     3
Parallelism:     No limit
Service account: ####

 

- Is the execution = container Id for Cloud Run ? centos-vdn9s in the above snapshot
- Isn't the container Id in uuid format as with other platforms like kubernetes . Or am I missing something ? 
- Additionally, is there a way to fetch this info from the running container deployed as a Job/Service. Something equivalent to Environment variables mentioned in https://cloud.google.com/run/docs/container-contract

its the uid -the non-programmatic method to see it is to goto Cloud Run -> yaml -> uid  if you deployed this to Artifact Registry it'll also have the URL with the version and hash, this information is under the gcloud describe - if you can't see it in the shell - I'm not sure other than potentially a permissions issue - but given the above you should be able to reverse it

ns2
Bronze 3
Bronze 3

Thanks @djs_75 .
Are you referring to the uid marked in the snapshot attached related to service with two containers.
If yes,  this identifier appears to be for service as a whole.
For a multi-container service, is it feasible  get the container Id(uid) for the individual containers

ns2_0-1708401902575.png

 

Or am I not accessing the correct tab ?


so if you're doing multiple containers - go to the revision tab --> select yaml and goto the spec of the container and the uid should be the container id

djs_75_0-1708445785561.png

if your spec has multiple containers within the service they each deploy with a readiness probe so you look at the log then parse the metadata for the id, annotation or label (this is based on your preference to manage or use case) and use that event for your liveiness probe, readiness (aka startup probe in cloud run) probe (which is the id or serviceid in the metadata) , or for eventarc to listen and trigger an action. Typically, if I need something for a specific instantiation, I'm automating it to pub/sub with eventarc  see the API Container  |  Cloud Run Documentation  |  Google Cloud and Using annotations and labels with Cloud Deploy  |  Google Cloud

djs_75_1-1708445956151.png

 

 

ns2
Bronze 3
Bronze 3

Hi @djs_75 , not sure if I'm missing something, I am unable to see the container Id in the spec.
Attaching the snapshot of a Revision->yaml of a service with two containers.

ns2_0-1708509271736.png

 

Cloud Run does not expose container id as a part of service or revision yaml. Could you describe the use case for fetching the container id?