Skip to content

Instantly share code, notes, and snippets.

@MatteoGioioso
Last active September 8, 2021 03:16
Show Gist options
  • Save MatteoGioioso/8c0a2fa39840e36e62558a58b632b535 to your computer and use it in GitHub Desktop.
Save MatteoGioioso/8c0a2fa39840e36e62558a58b632b535 to your computer and use it in GitHub Desktop.
Example Dockerfile for debugging golang application inside docker container
FROM public.ecr.aws/bitnami/golang:1.15 AS build-env
RUN go get github.com/go-delve/delve/cmd/dlv
# Copy the files here, be sure to include the go.mod file.
WORKDIR /app
RUN go build -gcflags="all=-N -l" -o /server
FROM debian:buster
EXPOSE 8000 40000
WORKDIR /
COPY --from=build-env /go/bin/dlv /
COPY --from=build-env /server /
CMD ["/dlv", "--listen=:40000", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "/server"]
#!/usr/bin/env sh
# Run the docker image
docker run --rm --name debug-go -p "8000:8000" -p "40000:40000" --security-opt="apparmor=unconfined" --cap-add=SYS_PTRACE <your image name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment