Languages & Frameworks·Last Verified: 2026-07-14
Go (Golang)
Deploy lightweight Go binaries using multi-stage builds.
Go services compile into extremely lightweight, high-performance container layers.
Go Multi-Stage Dockerfile
Go Multi-Stage build
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/main .
EXPOSE 8080
CMD ["./main"]Code Example
Go Port Bind
package main
import (
"fmt"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, Kubeletto!")
})
http.ListenAndServe("0.0.0.0:"+port, nil)
}Was this helpful?