Gothic Framework G symbol

Docker Setup

Gothic apps compile to a single Go binary, which means they can run anywhere — on any cloud, any VPS, or any container platform. Combined with the pluggable cache system (REDIS or IN_MEMORY) and self-served static files, you can deploy to any provider using Docker.

First, set the Runtime block in your gothic.config.go to use the REDIS cache strategy and serve static files in all environments. Your main.go then wires it up with a single line — router.Use(gothicServer.Middleware(Config.Runtime)):

package main

import (
	gothic "github.com/gothicframework/core/config"
	"os"
)

var Config = gothic.Config{
	ProjectName: "my-project",
	Runtime: gothic.RuntimeConfig{
		CacheStrategy:    gothic.REDIS,
		ServeStaticFiles: gothic.ALL_ENVS,
		CacheConfig: &gothic.CacheConfig{
			RedisURL: os.Getenv("REDIS_URL"),
		},
	},
}

Next, create a multi-stage Dockerfile for an optimized production image:

# Build stage — glibc base so GOTOOLCHAIN=auto can fetch the exact Go your go.mod needs
FROM golang:1.26 AS build

ENV GOTOOLCHAIN=auto
ENV GOWORK=off

WORKDIR /build

COPY go.mod go.sum ./
RUN go mod download
COPY . .

# Build the whole package (.), not main.go — Config lives in gothic.config.go.
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o ./server .

# Minimal production image
FROM scratch

WORKDIR /app
COPY --from=build /build/server /app/
COPY --from=build /build/public /app/public
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

EXPOSE 8080
CMD ["/app/server"]

Finally, use Docker Compose to run your app with Redis locally:

version: "3.8"
services:
  app:
    build: .
    ports:
      - "8080:8080"
    environment:
      - REDIS_URL=redis:6379
    depends_on:
      - redis
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

Ready to deploy? Let's start with Google Cloud Platform!