Last active
September 8, 2021 03:16
-
-
Save MatteoGioioso/8c0a2fa39840e36e62558a58b632b535 to your computer and use it in GitHub Desktop.
Example Dockerfile for debugging golang application inside docker container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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