Go
Deploy a Go app on DockHosting — build, port binding, and databases.
DockHosting detects a Go project from a go.mod at the repository root, builds a binary with go build, and runs it.
Requirements
go.mod(andgo.sum, committed — not gitignored) at the repository root- A
mainpackage that builds to a single binary DockHosting can run directly - Your app listening on the
PORTenvironment variable, bound to0.0.0.0
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Fatal(http.ListenAndServe("0.0.0.0:"+port, nil))Build tags and CGO
If your dependencies need CGO_ENABLED=1 (some SQLite drivers, for example), the default statically-linked build behavior may need adjusting — a build that succeeds locally with CGO enabled but fails or behaves differently in a CGO-disabled build environment is a common surprise. If you hit this, a Dockerfile gives you full control over the build environment.
Databases
pgx or lib/pq (Postgres), go-sql-driver/mysql (MySQL/MariaDB), the official mongo-driver (MongoDB), and go-redis all accept the connection string DockHosting injects when you attach a database to your project — pass it directly to sql.Open or the driver's connection constructor.
Environment variables
Read with os.Getenv("VARIABLE_NAME"). Set them in your project's settings — see Environment variables.
Long-running services
A Go binary that's a worker or a bot rather than an HTTP server needs the same consideration as any long-running process — see the note in Deploying → Node.js.