A web app in Go, with only the standard library. It answers on the port in PORT, which we set for each instance.
The app
main.go:
// A minimal web app: it answers on the port in PORT, which the platform sets.
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello from Go")
})
log.Printf("listening on %s", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
go.mod:
module example.com/hello
go 1.25
The Dockerfile
FROM golang:1.25-alpine AS build
WORKDIR /src
COPY go.mod ./
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /hello .
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /hello /hello
CMD ["/hello"]
It builds a static binary and copies it into a minimal image that runs as a user without privileges, so the image you deploy is a few megabytes.
Deploy it
You can deploy it two ways.
From GitHub
- Put these files in a repository on GitHub.
- In the dashboard, choose Create app, name it, and choose GitHub repository as its source. Pick the repository and branch.
- Keep the web process’s Port at 8080, or any port you like: your app reads it from
PORT. - Choose Create app. It builds your Dockerfile and deploys; every push to the branch does it again.
From an image you build
-
Build the image for 64-bit Linux, and push it to a registry you use, such as Docker Hub or GitHub’s:
docker build --platform linux/amd64 -t ghcr.io/you/hello-go:1 . docker push ghcr.io/you/hello-go:1 -
Choose Create app, name it, choose Container image, and enter the image in Image.
-
Keep the web process’s Port at 8080, and choose Create app.
Check it
Once its deploy succeeds, open https://hello-go.fireflyplus.site. It says:
Hello from Go