Appearance
Go
Go projects fall back to Nixpacks, which detects go.mod, uses the Go version from it, builds the module and runs the resulting binary.
Listen on $PORT
go
package main
import (
"log"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok")) })
log.Fatal(http.ListenAndServe(":"+port, nil))
}":"+port listens on all interfaces, which is what you want in a container.
Several binaries
If main packages live under cmd/, set a custom build command and start command, for example go build -o app ./cmd/server and ./app.
Using a Dockerfile
A multi-stage Dockerfile gives the smallest image:
dockerfile
FROM golang:1.25 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /app ./cmd/server
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /app /app
ENV PORT=8080
EXPOSE 8080
ENTRYPOINT ["/app"]