Distroless and stripped binaries
Distroless and scratch images
DebugHero works with distroless and scratch images. Your image does not need a shell, ps, or Delve.
The debug container brings its own tools. It uses targetContainerName, so it sees the processes of your container, and it reads your binary through /proc/<pid>/root. Nothing is copied into your container.
Stripped binaries
Delve needs the DWARF debug information in the binary. Some build flags remove it:
| Build | Breakpoints | Variables | Automatic path mapping |
|---|---|---|---|
go build | Yes | Yes. Some show as "optimized away". | Yes |
go build -gcflags="all=-N -l" | Yes | Yes, all | Yes |
go build -trimpath | Yes | Yes | No. See Map source paths. |
go build -ldflags="-w" | No | No | No |
go build -ldflags="-s -w" | No | No | No |
| Binary compressed with UPX | No | No | No |
To check that a binary has debug information, run file on it:
file ./checkout
./checkout: ELF 64-bit LSB executable, x86-64, ..., with debug_info, not stripped
If the output does not contain with debug_info, Delve cannot debug the binary.
Optimized code
By default, the Go compiler optimizes the code and inlines small functions. Delve can debug optimized code, but:
- some variables show as "optimized away",
- stepping can skip lines or jump between lines,
- breakpoints in inlined functions can behave unexpectedly.
-gcflags="all=-N -l" turns off optimizations (-N) and inlining (-l) for all packages. The binary is larger and slower. Use it for images that you plan to debug, not for every production image.
Build an image that you can debug
This example builds a distroless image with full debug information. WORKDIR /src makes /src the build directory, so the automatic path mapping works.
FROM golang:1.25 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -gcflags="all=-N -l" -o /out/checkout ./cmd/checkout
FROM gcr.io/distroless/static-debian12
COPY --from=build /out/checkout /checkout
ENTRYPOINT ["/checkout"]
Use Go 1.25 or older for now. See Go version.
A common pattern is to build two images from the same commit: a release image with the default flags, and a debug image with -gcflags="all=-N -l". Deploy the debug image to a development or staging environment when you need it.