Search code examples
dockergcloudgoogle-cloud-run

Gcloud and docker confusion


I am very lost on the steps with gcloud verse docker. I have some gradle code that built a docker image and I see it in images like so

(base) Deans-MacBook-Pro:stockstuff-all dean$ docker images
REPOSITORY                         TAG       IMAGE ID       CREATED          SIZE
gcr.io/prod-stock-bot/stockstuff   latest    b041e2925ee5   27 minutes ago   254MB

I am unclear if I need to run docker push or not or if I can go strait to gcloud run deploy so I try a docker push like so

(base) Deans-MacBook-Pro:stockstuff-all dean$ docker push gcr.io/prod-stockstuff-bot/stockstuff
Using default tag: latest
The push refers to repository [gcr.io/prod-stockstuff-bot/stockstuff]
An image does not exist locally with the tag: gcr.io/prod-stockstuff-bot/stockstuff

I have no idea why it says the image doesn't exist locally when I keep listing the image. I move on to just trying gcloud run deploy like so

(base) Deans-MacBook-Pro:stockstuff-all dean$ gcloud run deploy stockstuff --project prod-stock-bot --region us-west1 --image gcr.io/prod-stockstuff-bot/stockstuff --platform managed
Deploying container to Cloud Run service [stockstuff] in project [prod-stock-bot] region [us-west1]
X Deploying... Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
  X Creating Revision... Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
  . Routing traffic...
Deployment failed
ERROR: (gcloud.run.deploy) Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.

I am doing this all as a playground project and can't seem to even get a cloud run deploy up and running.

I tried the spring example but that didn't even create a docker image and it failed anyways with

ERROR: (gcloud.run.deploy) Missing required argument [--image]: Requires a container image to deploy (e.g. `gcr.io/cloudrun/hello:latest`) if no build source is provided.

Solution

  • This error occurs when an image is not tagged locally/correctly. Steps you can try on your side.

    • Create image locally with name stockstuff (do not prefix it with gcr and project name while creating).
    • Tag image with gcr repo detail
    $ docker tag stockstuff:latest gcr.io/prod-stockstuff-bot/stockstuff:latest
    
    • Check if your image is available in GCR (must see your image here, before deploying on cloudrun).
    $ gcloud container images list --repository gcr.io/prod-stockstuff-bot
    
    • If you can see your image in list, next you can try to deploy gcloud run with below command (as yours).
    gcloud run deploy stockstuff --project prod-stock-bot --region us-west1 --image gcr.io/prod-stockstuff-bot/stockstuff --platform managed