3

A team who worked on a project deployed a docker image to a cloud run service. I do not have the docker image but I have access to the Cloud Run service. I can see the logs and details. I would like to find the files that were in that docker image. How can I access this? For example the image contained a main.py file, now I want to access this.

Thanks

user147529
  • 555
  • 1
  • 7
  • 18

1 Answers1

15

Since Cloud Run uses docker images, you can use the GCP cloud shell (Cloud shell already has docker installed).

Also, you need get the container registry image used for your cloud run service, to get it, please follow this steps:

1.- Choose your service from the cloud run services list

2.- In the service page, go to revision tab.

3.- Click on image URL.

4.- In the image details page, click on Show Pull Command and the image used will have the following format gcr.io/[imagename] for example gcr.io/cloudrun/hello:latest

In cloud shell run the following command

docker run -it --entrypoint sh {image-name}

For example:

docker run -it --entrypoint sh gcr.io/cloudrun/hello

This command will open a new shell within your docker container (to exit hit, ctrl+d), run the command ls -lah to see the files within your docker image, to see the content of any file use the cat command.

*your google account used in Google Cloud Console must have access to the container registry image

Jan Hernandez
  • 4,414
  • 2
  • 12
  • 18
  • This is absolutely perfect. Thank you so much. Do you happen to know how to download the file from cloud shell? I've tried the command cloudshell download but it doesn't recognise cloudshell – user147529 Sep 07 '20 at 10:01
  • This is a good question, first you need to move the file from the docker container to cloud shell vm, please check this [answer](https://stackoverflow.com/a/22050116/11529321) – Jan Hernandez Sep 07 '20 at 14:22
  • Thank you so much, you're so kind. It's rare for someone on Stack overflow to say I have a good question haha – user147529 Sep 07 '20 at 21:42
  • Hi I need some help. I'm trying to run sudo docker gcr.io/cloudrun/hello/main.py . but it's saying no such container path exists. Any idea? Thanks – user147529 Sep 08 '20 at 10:49
  • @user147529 can you open a new question with more details? – Jan Hernandez Sep 09 '20 at 13:58
  • Yes it's definetely work - thanks for that – Piotr Żak Oct 31 '21 at 11:49
  • 1
    Hi @JanHernandez and others. In the pull tab, my image is of the format `europe-west1-docker.pkg.dev/bb-123/cloud-run-source-deploy/myservice` I go to the revisions tab. Click on the Image URL (right hand side, Container -> General -> Image URL). That takes me to Artifact Registry. I have a 'pull' tab that I then select and that is where I see the 'pull by tag' and 'pull by digest' neither of which has the gcr.io prefix. Wehn I run `docker run -it` I get and `unable to find image` error. Any ideas? – atreeon Jun 11 '22 at 08:27