DEV Community

Cover image for DevPill #2: How to build and push a docker image to google cloud Artifact Registry
Raul Paes Silva
Raul Paes Silva

Posted on

DevPill #2: How to build and push a docker image to google cloud Artifact Registry

  1. Specify Dockerfile. Example:

    FROM golang:1.25 AS builder
    WORKDIR /app
    COPY . .
    WORKDIR /app/services/api-gateway/cmd
    RUN CGO_ENABLED=0 GOOS=linux go build -o api-gateway
    
    FROM alpine:latest
    RUN apk --no-cache add ca-certificates
    WORKDIR /root/
    COPY --from=builder /app/services/api-gateway/cmd/api-gateway .
    CMD ["./api-gateway"]
    
  2. Docker "build" to create the image locally. Example:

    docker build -t us-central1-docker.pkg.dev/<project-id>/<repository-name>/api-gateway:latest --platform linux/amd64 -f infra/production/docker/api-gateway.Dockerfile .

  3. Push image to Google Cloud Artifact Registry:

    docker push us-central1-docker.pkg.dev/<project-id>/<repository-name>/api-gateway:latest

Now your image will be available to any GCP service you would like to use.

Top comments (0)