This post assumes you have already signed up for google cloud and you have already installed gcloud and docker on your computer, there are so many articles and videos to follow so this should not be an issue.
1. Create an artifact Registiry
Type Artifact Registry in the search bar , and you will get the see Artifact Registry in the drop down click that
Click "create repository" and give it a new name, select the region were the Artifact Registry will be hosted
Then copy the path of your artifact registry so that you can use it to create a docker image you can find this by clicking your artifact registry and then click the copy icon
2. Build the docker image
When building your docker image don't forget to specify the platform especially when you are using M1, M2, M3 macbook.Google cloud is expecting a linux/amd64 image if its not that your image will fail to deploy and you will get an error that looks something like Application failed to start: failed to load /bin/sh: exec format error
in the logs.
docker build -t updated-sample-image . --platfrom linux/amd64
After that tag your docker image , so that it can have a name which google cloud expects, it should basically be the in the path of the artifact registry that you copied above,
for example here i added
/update-container:v1.1.0
then adding the full path plus the name of the image becomes
us-central1-docker.pkg.dev/poetic-inkwell-404816/step-by-step/update-container:v1.1.0
Don't forget to add a version otherwise it defauts to lastest
tag so when you do docker push
you will have an error here i used the v1.1.0
tag, but it can be any version number you like.
docker tag updated-sample-image \us-central1-docker.pkg.dev/poetic-inkwell-404816/step-by-step/update-container:v1.1.0
Then push the docker image to the docker repository
docker push us-central1-docker.pkg.dev/poetic-inkwell-404816/step-by-step/updated-container:v1.1.0
3. Deploy the docker image
Finally lets push the docker image to the google cloud
gcloud run deploy --image us-central1-docker.pkg.dev/poetic-inkwell-404816/step-by-step/updated-container:v1.1.0
You may get few erros here , make sure the account that you are using has permissons to push to google cloud and if you get gcould Permission denied by location policies.
just change the server you want to deploy this to when you click gcloud run deploy.
There you go, by now it should give you a link to check out your project remember if you want this to be publically available you need to change the settings in Cloud run
, to find Cloud run
search cloud run and then click "cloud run"
find the name of the container , in this case we called it "updated-container" and click security and change the settings to Allow unauthenticated invocations
Top comments (0)