Gothic Framework G symbol

Customize Dockerfile

When you run gothic deploy, the CLI uses the template at .gothicCli/templates/Dockerfile-template to build your container image. You can edit this file to add system dependencies, change the base image, or tweak the build process — the changes apply on the next deploy.

Default Template

The default Dockerfile is a multi-stage build: it compiles your Go binary in golang:alpine, then copies it into a minimal scratch image alongside the AWS Lambda Web Adapter.

# Build binary 
 FROM  golang:alpine  AS  build

 WORKDIR  /build

 COPY  go.mod go.sum ./
 COPY  . .

 RUN  apk add --no-cache ca-certificates

 RUN  GOOS=linux go build -ldflags= "\"-w -s\""  -o ./main main.go

 # Start lambda container from fresh image 
 FROM  scratch

 WORKDIR  "/var/task"
 COPY  --from=build /build/main /var/task
 COPY  --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

 COPY  --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.7.0 /lambda-adapter /opt/extensions/lambda-adapter

 CMD  [ "/var/task/main" ] 

Example 1 — Add a System Dependency

If your app needs a native library at build time (for example, ffmpeg for video processing), add a RUN apk add line in the build stage:

# Build binary 
 FROM  golang:alpine  AS  build

 WORKDIR  /build

 COPY  go.mod go.sum ./
 COPY  . .

 RUN  apk add --no-cache ca-certificates
 RUN apk add --no-cache ffmpeg 

 RUN  GOOS=linux go build -ldflags= "\"-w -s\""  -o ./main main.go

 # Start lambda container from fresh image 
 FROM  scratch

 WORKDIR  "/var/task"
 COPY  --from=build /build/main /var/task
 COPY  --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

 COPY  --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.7.0 /lambda-adapter /opt/extensions/lambda-adapter

 CMD  [ "/var/task/main" ] 

Because the final image is scratch, only the compiled binary ships to Lambda — build-time dependencies do not increase your production image size.

Example 2 — Use Alpine as Runtime

If your app needs a shell or system libraries at runtime (for example, for debugging or calling external binaries), replace scratch with alpine in the final stage. Remember to install ca-certificates in the runtime stage as well:

# Build binary 
 FROM  golang:alpine  AS  build

 WORKDIR  /build

 COPY  go.mod go.sum ./
 COPY  . .

 RUN  GOOS=linux go build -ldflags= "\"-w -s\""  -o ./main main.go

 # Runtime image with shell access 
 FROM alpine 

 RUN apk add --no-cache ca-certificates 

 WORKDIR  "/var/task"
 COPY  --from=build /build/main /var/task

 COPY  --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.7.0 /lambda-adapter /opt/extensions/lambda-adapter

 CMD  [ "/var/task/main" ] 

Using alpine adds ~8 MB to the image but gives you a full package manager and shell. This is useful for apps that shell out to tools like ffmpeg, imagemagick, or wkhtmltopdf at runtime.

Next, learn how to customize the SAM template to add AWS resources!