If you don’t already have one, create an Artifact Registry:
gcloud artifacts repositories create your-repo-name \
--repository-format=docker \
--location=europe-west2 \
--description="your-repo-description" \
--immutable-tags \
--async
Authorize gcloud cli access to the registry in your region:
gcloud auth configure-docker europe-west2-docker.pkg.dev
This adds config to $HOME/.docker/config.json, you can look in this file to see what GCP registries you have already authenticate with.
The image you’re deploying needs to listen on port 8080, and needs to be built for linux/amd64. If you’re building on an Apple Silicon Mac, build your image with:
docker build . --platform linux/amd64 -t image-tag-name
Tag the image ready to push to your registry:
docker tag SOURCE-IMAGE LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE:TAG
where:
LOCATION = GCP region, e.g. europe-west2
Authenticate your local Docker with your GCP Artifact Repository:
gcloud auth configure-docker LOCATION-docker.pkg.dev
Push your image to the Artifact Repository with:
docker push LOCAITION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE:TAG
After pushing you can browse your Artifact Registry in the Console and see your image there.
To deploy a new service using the image you just pushed:
gcloud run deploy gcp-nginx-test --project your-project-name --image LOCAITION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE:TAG
These steps are a summary of the Artifact Registry docs here, and the Cloud Run docs here.