Skip to content

Go Deployment — Deploying Go Applications with Docker, Multi-stage Builds, and CI/CD

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you will learn about Go Deployment. We cover key concepts, practical examples, and best practices to help you master this topic.

Go deployment uses Docker multi-stage builds for small images, CI/CD pipelines with testing, and cloud platform deployment to AWS, GCP, and Fly.io.

What You'll Learn

  • Docker multi-stage builds
  • CI/CD pipeline setup
  • Cloud platform deployment
  • Binary distribution

Why It Matters

Deployment delivers your app to users. Docker ships as a Go binary. Kubernetes components deploy as containers. DodaZIP deploys Go services via Docker.

Real-World Use

Microservice deployment, Serverless functions, CLI tool distribution, Edge Computing.

Docker Multi-stage Build

FROM golang:1.22 AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o app .

FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/app .
EXPOSE 8080
CMD ["./app"]

Build Small Binary

CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o app .
upx app  # Compress further (optional)

CI/CD Pipeline

name: Go CI/CD
on: [push]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: '1.22'
      - run: go test -race -cover ./...

  build:
    needs: test
    steps:
      - uses: actions/checkout@v4
      - name: Build binary
        run: GOOS=linux GOARCH=amd64 go build -o app .
      - name: Deploy
        run: scp app user@server:/opt/app

Cloud Run Deployment

# cloudbuild.yaml
steps:
  - name: gcr.io/cloud-builders/docker
    args: ['build', '-t', 'gcr.io/$PROJECT_ID/app', '.']
  - name: gcr.io/cloud-builders/docker
    args: ['push', 'gcr.io/$PROJECT_ID/app']
  - name: gcr.io/google.com/cloudsdktool/cloud-sdk
    entrypoint: gcloud
    args:
      - run
      - deploy
      - app
      - --image=gcr.io/$PROJECT_ID/app
      - --platform=managed
      - --region=us-central1
Topic Description Link
Go Modules Module management {{< ref "37-modules" >}}
Go CLI Apps Building CLI tools {{< ref "39-cli-apps" >}}
Go Mini Projects Build real apps {{< ref "45-mini-projects" >}}

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro

Home Browse Go