Skip to main content

GCloud | Artifact Registry | Quick Essentials

https://cloud.google.com/artifact-registry/docs/docker/store-docker-container-images#gcloud

# To Create a new repository
gcloud artifacts repositories create quickstart-docker-repo --repository-format=docker \
--location=us-central1 --description="Docker repository"


gcloud artifacts repositories list

export REPO=art-reg-windycreek

# One time step - Configure authentication for docker
# Update region
gcloud auth configure-docker us-west1-docker.pkg.dev


kre-> cat /home/kre/.docker/config.json
{
"auths": {},
"credsStore": "desktop",
"currentContext": "default",
"credHelpers": {
"us-west1-docker.pkg.dev": "gcloud"
}
}

Sample Docker Image Build

Sample Dockerfile for a Nodejs app (non-React type)

FROM node:lts-alpine3.17

RUN apk update && \
apk upgrade && \
apk add --no-cache bash git openssh

RUN mkdir /app
WORKDIR /app
COPY package.json .
RUN npm install

COPY . .

ENV SERVER_PORT=8000

EXPOSE 8000

CMD ["npm", "start"]

Docker build and run script sample

#!/usr/bin/env bash
docker build -t jwt-auth-server .
docker run --init -p 8000:8000 -it jwt-auth-server

Add Image to Registry

Trouble shooting: Make sure docker is not run with sudo. Credentials won't pass otherwise

Tip: Copy the full registry path from console, shown below
console

Tip: ctrl+x+e in bash to edit the command in the default editor

# Tag it -  this is the key step
docker tag wapp-erealms-cli-server \
us-west1-docker.pkg.dev/cloudworks22/art-reg-windycreek/wapp-erealms-cli-server:0.1.0-beta1

# List all images and tags
docker image ls

# Push to registry
# Make sure
docker push us-west1-docker.pkg.dev/cloudworks22/art-reg-windycreek/wapp-erealms-cli-server:0.1.0-beta1