How to Deploy your Go (Golang) API to the Cloud
Go is famous for its performance, concurrency, and static binaries. When deployed correctly using Docker, a compiled Go API can use negligible RAM while serving thousands of requests.
The Multi-Stage Docker Build
Because Go compiles to a static binary, your production container doesn't need the Go SDK, saving hundreds of megabytes in image size. Here is an optimized `Dockerfile`.
# Build stage
FROM golang:1.21-alpine AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
# Final stage
FROM alpine:3.18
WORKDIR /root/
COPY --from=build /app/main .
EXPOSE 8080
CMD ["./main"]
Important Port Configuration
When running the standard library net/http or a framework like Gin, ensure you bind to a generic
IP so the container recognizes incoming traffic:
port := os.Getenv("PORT")
if port == "" { port = "8080" }
http.ListenAndServe("0.0.0.0:" + port, nil)
Cloud Integration
Commit your `main.go` and `Dockerfile` to GitHub. Log into your dashboard on a modern PaaS like Remoud and deploy the repository. The platform compiles the binary, creates a tiny Alpine image, assigns proper SSL certs, and boots your server instantly.
Ship Faster
Go paired with Remoud's Git-based rollout simplifies enterprise deployments dramatically.
Start deploying for free →