I believe there might be an issue in this scenario. Here's what I've done:
c:\repos\demogo mod init demo, here is the mod file
module demo
go 1.22.0
main.go file in the folder
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World!")
})
http.ListenAndServe(":8080", nil)
}
http://localhost:8080 to hit my breakpoint.FROM golang:1.22.0
WORKDIR /app
COPY . .
RUN go install github.com/go-delve/delve/cmd/dlv@latest
EXPOSE 40000 8080
CMD ["dlv", "debug", "--headless", "--listen=:40000", "--api-version=2", "--accept-multiclient", "--log"]
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 40000,
"host": "127.0.0.1"
}
]
}
docker build -t demo .
docker run -p 40000:40000 -p 8080:8080 demo
Connect to server to remote debug
PS C:\repos\demo> docker run -p 40000:40000 -p 8080:8080 demo
2024-02-16T04:46:42Z warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
2024-02-16T04:46:42Z info layer=debugger launching process with args: [./__debug_bin4263375465]
API server listening at: [::]:40000
2024-02-16T04:46:42Z debug layer=debugger Adding target 1534 "/app/__debug_bin4263375465"
2024-02-16T04:46:50Z debug layer=debugger continuing
2024-02-16T04:46:50Z debug layer=debugger ContinueOnce
2024-02-16T04:46:59Z debug layer=debugger halting
2024-02-16T04:46:59Z warning layer=debugger gnu_debuglink link "ce4e6e4ef08fa58a3535f7437bd3e592db5ac0.debug" not found in any debug info directory
2024-02-16T04:46:59Z warning layer=debugger gnu_debuglink link "e7d4a67acf053c794b3b8094e6900b5163f37d.debug" not found in any debug info directory
2024-02-16T04:46:59Z debug layer=debugger callInjection protocol on:
2024-02-16T04:46:59Z debug layer=debugger 1534 PC=0x405e8e
2024-02-16T04:46:59Z debug layer=debugger 1542 PC=0x4795a3
2024-02-16T04:46:59Z debug layer=debugger 1543 PC=0x4795a3
2024-02-16T04:46:59Z debug layer=debugger 1544 PC=0x4795a3
2024-02-16T04:46:59Z debug layer=debugger 1545 PC=0x4795a3
2024-02-16T04:46:59Z debug layer=debugger continuing (direction congruent)
2024-02-16T04:46:59Z debug layer=debugger ContinueOnce
I attempted to run the same code about a month ago, and everything worked perfectly. However, this time it seems to be broken. I'm not certain if anything has changed recently.
That worked for me - open VSCode user's settings.json file and add there:
"go.delveConfig": {
"debugAdapter": "legacy",
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With