GoLand调试器不会在Docker容器中调试go代码时在源代码中停止

时间:2018-11-08 05:15:42

标签: docker go goland delve

我正在使用:

Mac os High sierra 10.13.6
Docker Community Edition 18.06.1-ce
GoLand 2018.2.3
Go 1.11.1 (installed by brew at /usr/local/Cellar/go/1.11.1/libexec

enter image description here 我正在按照https://blog.jetbrains.com/go/2018/04/30/debugging-containerized-go-applications/上的说明从GoLand IDE远程调试在Docker容器中运行的go代码。

但是,调试器不会在调用http://localhost:8080

时停止源代码

enter image description here

如果我使用Dockerfile.1,则在运行容器时会看到此错误:

Could not create config directory: user: Current not implemented on linux/amd64.

如果我使用Dockerfile.2,则在运行容器时看不到任何错误。

但是,调试器不会在源代码中的任何断点处停止。

---- Dockerfile.1 ----

FROM golang:1.10.1-alpine3.7 AS build-env
ENV CGO_ENABLED 0
ADD . /go/src/hello

RUN go build -gcflags "all=-N -l" -o /server hello

RUN apk add --no-cache git
RUN go get github.com/derekparker/delve/cmd/dlv

FROM alpine:3.7

EXPOSE 8080 40000

RUN apk add --no-cache libc6-compat

WORKDIR /

COPY --from=build-env /server /
COPY --from=build-env /go/bin/dlv /

CMD ["/dlv", "--listen=:40000", "--headless=true", "--api-version=2", "exec", "/server"]

---- Dockerfile.2 ----

FROM golang:1.10.1-alpine3.7 AS build-env
ADD . /go/src/hello

RUN apk add --no-cache libc6-compat build-base

RUN go build -gcflags "all=-N -l" -o /server hello

RUN apk add --no-cache git
RUN go get github.com/derekparker/delve/cmd/dlv

FROM alpine:3.7

EXPOSE 8080 40000

RUN apk add --no-cache libc6-compat

WORKDIR /

COPY --from=build-env /server /
COPY --from=build-env /go/bin/dlv /

CMD ["/dlv", "--listen=:40000", "--headless=true", "--api-version=2", "exec", "/server"]

0 个答案:

没有答案