Hosting a Go Gin web app with Serverless Containers
Gin is a lightweight, high-performance web framework for Go, ideal for building fast APIs and web applications with minimal overhead. Hosting Gin apps on Scaleway Serverless Containers provides automatic scaling, simplified deployment, and reduced infrastructure management. This deployment method enables your application to efficiently handle varying workloads, optimize resource usage, and lets you focus on writing code and building features rather than maintaining servers.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- Installed Docker or Docker Engine
- Created a Scaleway Container Registry namespace and logged into it
- Installed go 1.23 or newer
Create and host a basic Go Gin web application
To host a Go web application using the Gin framework on Scaleway Serverless Containers, you need to create a simple Go project, define HTTP handlers, and containerize it using a production-ready Dockerfile. After building the container image locally, push it to the Scaleway Container Registry and deploy it via Scaleway Serverless Containers.
Gin is a lightweight, high-performance web framework for Go, ideal for building fast APIs and web apps with minimal overhead.
Create your app and test it locally
-
In a terminal, create a new directory and navigate into it:
mkdir my-gin-app cd my-gin-app -
Initialize a Go module:
go mod init my-gin-app -
Create a
main.gofile, then add the code below to it to create a basic Gin server:package main import "github.com/gin-gonic/gin" func main() { r := gin.Default() r.LoadHTMLGlob("templates/*") r.GET("/", func(c *gin.Context) { c.HTML(200, "index.html", nil) }) r.Run("0.0.0.0:8080") } -
Create a
templatesfolder to store HTTP files.mkdir templates -
Create an
index.htmlfile in thetemplatesfolder, then add the code below to it:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>Hello</title> <style> body { font-family: sans-serif; text-align: center; margin: 0; padding: 100px 20px; background: #fafafa; color: #333; } </style> </head> <body> <h1>Hello from Gin 🌿</h1> <p>A minimal page, fast and clean, running on Scaleway Serverless Containers.</p> </body> </html> -
Run the following command to install the Gin package:
go get -u github.com/gin-gonic/gin -
Test the app locally:
go run main.goVisit http://localhost:8080 to see the homepage of your web app.
Build the app image and push it to Scaleway Container Registry
Before building and pushing your image, ensure you have created a Scaleway Container Registry namespace, and logged into it with the Docker CLI.
-
Create a
Dockerfileat the root of your project:# Use a lightweight Go image for building FROM golang:1.25-alpine AS builder # Set working directory WORKDIR /app # Copy go mod files COPY go.mod go.sum ./ RUN go mod download # Copy source code COPY . . # Build the Go binary RUN go build -o main . # Final stage: minimal image FROM alpine:latest # Install CA certificates RUN apk --no-cache add ca-certificates # Set working directory WORKDIR /root/ # Copy binary from builder stage COPY /app/main . # Expose port EXPOSE 8080 # Run the binary CMD ["./main"] -
Build, tag, and push the image to Scaleway Container Registry:
docker build \ --platform linux/amd64 \ --push \ -t <CONTAINER_REGISTRY_ENDPOINT>/my-gin-app:latest .
Deploy your app using Serverless Containers
-
Deploy a Serverless Container with the following settings:
- Registry: Scaleway Container Registry
- Registry namespace: The namespace where you pushed your image
- Container port:
8080(matches the port in the Go app and Dockerfile) - Resources:
250 mVCPUand256 MBmemory (Go apps are lightweight) - Autoscaling: Set minimum scale to
1to avoid cold starts (optional)
Deployment may take up to a minute.
-
Once the container is ready, click the container endpoint in the Overview tab. Your Gin app will be live and accessible to anyone with the link.
Going further
- You can deploy an existing Go Gin project by building and pushing its container image as shown above.
- Add a custom domain to your deployed app.
- Secure your app with HTTPS — Scaleway automatically provides TLS for container endpoints.
Visit our Help Center and find the answers to your most frequent questions.
Visit Help Center