3.2.2 Uploading your container

View in the book. Buy the book.

Now it’s time to upload your container to a container registry.

Create a new repo

Go to https://console.cloud.google.com/artifacts and create a new repository of type Docker in your desired location.

Create Artifact Registry

Use the UI to copy the path that is generated, which will look something like us-west1-docker.pkg.dev/gke-autopilot-test/timeserver.

Create Artifact Registry

Authenticate

Cloud Shell is configured automatically. On other environments, take the host from that path, and use it here to authenticate docker:

HOST_NAME=us-west1-docker.pkg.dev
gcloud auth configure-docker $HOST_NAME

Tag

Append the image name and version timeserver:1 to the repository path. For example for the path us-west1-docker.pkg.dev/gke-autopilot-test/timeserver you would use us-west1-docker.pkg.dev/gke-autopilot-test/timeserver/timeserver:1

You can tag an existig image, like so (where timeserver was the previous tag).

IMAGE_TAG=us-west1-docker.pkg.dev/gke-autopilot-test/timeserver/timeserver:1
docker tag timeserver $IMAGE_TAG

List your local images to find those tags

$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
timeserver   latest    7f15ce6d0d5b   4 seconds ago   1.02GB

No existing image? No problem. Build and tag at the same time:

IMAGE_TAG=us-west1-docker.pkg.dev/gke-autopilot-test/timeserver/timeserver:1
cd Chapter02/timeserver
docker build . -t $IMAGE_TAG

Push

Once authenticated and tagged correctly, you can push the image

$ docker push $IMAGE_TAG
The push refers to repository [us-west1-docker.pkg.dev/gke-autopilot-test/timeserver/timeserver]
5f70bf18a086: Pushed 
df69a0f30478: Pushed 
701d0b971f5f: Pushed 
619584b251c8: Pushed 
ac630c4fd960: Pushed 
86e50e0709ee: Pushed 
12b956927ba2: Pushed 
266def75d28e: Pushed 
29e49b59edda: Pushed 
1777ac7d307b: Pushed 
1: digest: sha256:d679fbd18395da53b5bad05457f992b334fc230398f94e3aa906378d996646bd size: 2420

The image should now be in Artifact Registry

Create Artifact Registry