Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull Docker Hub image to Google Cloud Run?

I'm trying to pull Docker images into Google Cloud Run. I see that I would probably need to pull it first to Google Container registry, but can I somehow avoid it? Also, I'd rather have it straight from the source to have it up-to-date.

enter image description here

like image 500
jean d'arme Avatar asked Feb 22 '21 13:02

jean d'arme


People also ask

How do I pull images from Docker Hub?

Most of your images will be created on top of a base image from the Docker Hub registry. Docker Hub contains many pre-built images that you can pull and try without needing to define and configure your own. To download a particular image, or set of images (i.e., a repository), use docker pull .

How do I run a Docker container in Google cloud?

Head over to the Google Cloud Platform Console, and select “Create Service.” Select the region that you want it to run in, and give it a name. You can also choose to secure this container with Cloud IAM.


1 Answers

I got a look on the project and finally I successfully run it on Cloud Run

Firstly, you can't pull image outside Google Container Registry or Artifact Registry. So you need to pull the image, tag it and push it in GCP (your project or not, but on GCP)

Here the steps

# Pull the image (I did it on Cloud Shell)
docker pull thecodingmachine/gotenberg:6

# Tag the image
docker tag thecodingmachine/gotenberg:6 gcr.io/<MY_PROJECT_ID>/thecodingmachine/gotenberg:6

#Push the image (no authentication issue on Cloud Shell)
docker push gcr.io/<MY_PROJECT_ID>/thecodingmachine/gotenberg:6

# Deploy on Cloud Run
gcloud run deploy --image=gcr.io/<MY_PROJECT_ID>/thecodingmachine/gotenberg:6 \
  --port=3000 --region=us-central1 --allow-unauthenticated --platform=managed \
  --command=gotenberg gotenberg

The trick on the Cloud Run deployment is:

  • You need to specify the port, not use the default 8080, it's the 3000 here
  • You need to specify the command explicitly. By default, the entrypoint is used (the /tini) and the container should be not well built because there is permission issue. More detail in the Dockerfile

So then, use the Cloud Run URL instead of the http://localhost:3000 that you have in the documentation and enjoy!

like image 171
guillaume blaquiere Avatar answered Sep 22 '22 14:09

guillaume blaquiere