HO与DLV和MODD在Docker上进行调试
我正在 Docker 上运行 Go 应用程序,并希望使用 VSCode 通过 DLV 对其进行调试同时使用 MODD 进行应用程序重建。到目前为止我不知道如何连接到调试器。
Docker:
FROM golang:1.18 as dev
WORKDIR /root
RUN GO111MODULE=on go install github.com/cortesi/modd/cmd/modd@latest
RUN go install github.com/go-delve/delve/cmd/dlv@latest
COPY . .
CMD modd
MODD:
**/*.go !**/*_test.go {
prep: go build -o app main.go
prep: dlv exec --headless --continue --listen localhost:2345 --accept-multiclient ./app
daemon +sigterm: ./app
}
DOCKER_COMPOSE (暴露端口):
ports:
- "5000:5000"
- "2345:2345"
VSCode 配置:
{
"name": "Connect to Go server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "${workspaceFolder}",
"port": 2345,
"host": "127.0.0.1",
}
问:如何使用 MODD 让 DLV 在 Docker 上工作?
谢谢!
I'm running a Go app on the Docker and want to use VSCode to debug it via DLV at the same time using MODD for app rebuild. So far I cannot figure out how to connect to the debugger.
Docker:
FROM golang:1.18 as dev
WORKDIR /root
RUN GO111MODULE=on go install github.com/cortesi/modd/cmd/modd@latest
RUN go install github.com/go-delve/delve/cmd/dlv@latest
COPY . .
CMD modd
MODD:
**/*.go !**/*_test.go {
prep: go build -o app main.go
prep: dlv exec --headless --continue --listen localhost:2345 --accept-multiclient ./app
daemon +sigterm: ./app
}
DOCKER_COMPOSE (expose port):
ports:
- "5000:5000"
- "2345:2345"
VSCode configuration:
{
"name": "Connect to Go server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "${workspaceFolder}",
"port": 2345,
"host": "127.0.0.1",
}
Q: How to make DLV work on Docker with MODD?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,据我所知,做你想做的事情并不简单,因为你必须观察主机中文件的更改才能触发容器内的 dlv,从而扰乱 vscode 正在进行的调试会话。
这是设置 vscode 来调试容器中的应用程序并使用 modd 在文件更改时在容器内重新启动调试的hacky方法。
(确保您的主机中安装了 modd)
.vscode/launch.json
.vscode/tasks.json - 此文件将指示 vscode 通过以下方式运行容器docker compose 并在后台运行 modd
docker-compose.yml
Dockerfile
dlv.txt - 此文件将用于调用 dlv 来重建并继续
modd.conf - modd 会将所有文件复制回容器并发出重建并继续命令到正在运行的 dlv
您将能够设置断点和所有内容,但您会注意到有时您需要手动暂停并继续恢复调试会话。
Well, afaik it is not trivial to do what you want, because you have to watch files being changed in your host to trigger dlv inside the container, messing up with vscode's ongoing debug session.
Here is hacky way to setup vscode to debug app in container and use modd to restart debug inside the container on file change.
(Make sure you have modd installed in your host machine)
.vscode/launch.json
.vscode/tasks.json - This file will instruct vscode to run your container via docker compose and to run modd in background
docker-compose.yml
Dockerfile
dlv.txt - This file will be used to call dlv to rebuild and continue
modd.conf - modd will copy all files back to the container and issue a rebuild and continue command to the running dlv
You'll be able to set breakpoints and everything, but you'll notice that sometimes you'll need to manually pause and continue to recover the debugging session.