guides
Deploy a Go App
Deploy any Go application to Runix — from simple HTTP servers to full web frameworks.
Go apps are a great fit for Runix. They compile to a single binary, start instantly, and use minimal memory. Runix detects your Go project from go.mod and builds it automatically.
Prerequisites#
- A Go project with a go.mod file
- A Runix account (sign up free at runixcloud.dev)
Example Project#
Here's a minimal Go HTTP server. If you already have a Go project, skip to the configuration step.
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 from Runix!")
})
fmt.Printf("Server running on port %s\n", port)
http.ListenAndServe(":"+port, nil)
}module github.com/yourname/my-go-app
go 1.22Configuration#
Run runix init and Runix detects Go from your go.mod file:
name: my-go-app
services:
- name: api
type: web-service
repo: https://github.com/yourname/my-go-app
branch: mainHow It Works#
- 1.Runix detects Go from your go.mod file
- 2.It generates a multi-stage Dockerfile (build stage + minimal runtime image)
- 3.Your app is compiled with CGO_ENABLED=0 for a static binary
- 4.The final image is tiny (often under 20MB) since it only contains your binary
- 5.Your app is deployed with a public HTTPS URL
Go apps on Runix typically have the fastest cold-start times and lowest memory usage. If performance matters, Go is an excellent choice.
Environment Variables#
| Variable | Set By | Description |
|---|---|---|
| PORT | Runix (automatic) | The port your app should listen on. Read it with os.Getenv("PORT"). |
Common Issues#
App not responding (not listening on $PORT)#
The most common issue with Go apps is hardcoding the port instead of reading it from the PORT environment variable. Always use os.Getenv("PORT"):
// Good
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
http.ListenAndServe(":"+port, nil)
// Bad - hardcoded port
http.ListenAndServe(":8080", nil)Listening on localhost only#
Make sure you listen on all interfaces (0.0.0.0), not just localhost. Inside a container, localhost means only the container itself can connect.
// Good - listens on all interfaces
http.ListenAndServe(":"+port, nil)
// Bad - only listens on localhost
http.ListenAndServe("localhost:"+port, nil)