Run with Docker

If you build your application in production using docker, there are certain system dependencies required, namely:


apt update && apt install -y libffi-dev zlib1g-dev libedit-dev libc++-13-dev libc++abi-13-dev


apk add --no-cache gcc musl-dev zlib-static build-base
Most of these are already present in the official Golang docker images.
Important points to ensure in your Dockerfile:
  • Enable CGO while building your application. (default is enabled)
  • Remember to add the build flags: -gcflags="all=-N -l"
  • Install system dependencies.
Here is a sample Dockerfile to deploy our agent in your application.
FROM golang:1.20
# Set destination for COPY
# Install necessary system dependencies, including zlib1g-dev
RUN apt-get update && apt-get install -y zlib1g-dev
# Download Go modules
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code. Note the slash at the end, as explained in
# https://docs.docker.com/engine/reference/builder/#copy
COPY *.go ./
# Build
RUN CGO_ENABLED=1 GOOS=linux go build -gcflags="all=-N -l" -o /app
# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
# Run
CMD ["/app"]