Debug via Makefile
Answered
I have configured my Run configuration to run the application with Makefile. However I cannot run the application in Debug mode. Is there any configuration that I should add to my Makefile?
COMPOSE_ENV := DOCKER_HOST_IP=$$(make -s --no-print-directory hostip) SSH_KEY=$$(cat ~/.ssh/id_rsa)
.PHONY: ldev-backend
ldev-backend:
docker network create -d bridge ldev-backend || true
.PHONY: up
up: ldev-backend
ENTRY="make docker-ldev" ${COMPOSE_ENV} docker-compose-v1 -f docker-compose-ldev.yml up
I have seen similar problems on the web but they are mostly about C/C++ e.g:
https://stackoverflow.com/questions/8663313/debug-makefile-project-in-eclipse/12790893#12790893
Please sign in to leave a comment.
Hello,
You can attach the debugger to a process inside the Docker container, please see https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html#attach-to-a-process-in-the-docker-container
Pay attention that you don't need to use Dockerfile configuration and you can continue to use Makefile, but you should run your container with parameters that are specified in the article (especially --security-opt="apparmor=unconfined" --cap-add=SYS_PTRACE).
There is no direct way to debug your application that you run via Makefile right from the IDE since it is not a Go process.
I hope it helps.
Hi Daniil. I added --security-opt="apparmor=unconfined" --cap-add=SYS_PTRACE to my docker-compose file:
Now my question is, should I also follow step 3 in the post that you shared?:
Step 3. Create the Go Remote run/debug configuration
If yes, then what should be the port for debugger?
Many thanks.
Speaking about docker-compose, there is a how-to instruction: https://blog.jetbrains.com/go/2020/05/08/running-go-applications-using-docker-compose-in-goland/
The port should be the same as specified in your docker-compose file, e.g. please see https://github.com/dlsniper/dockerdev/blob/compose-debug/docker-compose.yaml. With the following docker-compose, your port bindings for Go remote configuration is 40000.
Hi Daniil,
So I added necessary permissions and port 40000 in my docker-compose file:
I rebuilt the project and run it with make command. After that I ran the remote debugger configuration (with Host: localhost and Port: 40000). I got the following error
Then I added a code to my project to listen on port 40000. Now I am not getting the error above but I can't see debugger actions in my breakpoints:
Is there anything I am missing, or why doesn't debugger start without adding the code to listen on port 40000?
Hello,
Have you added dlv debugger command execution as well? Please see https://github.com/dlsniper/dockerdev/blob/compose-debug/docker-compose.yaml#L16. You can try to run the following project in your environment to confirm that it'll suit your needs.
I added the debugger command execution as well:
But got these errors:
Also, I cloned the project that you sent and tried to attach the debugger to the docker container but got this
Things I did:
1. Added necessary options in Run configs
2. Added Remote config for the debugger:
3. Exposed PORT 40000 in Dcokerfile
4. Ran the Docker Configuarion
5. Ran Debugger in remote configuration
Could you please collect the IDE logs via Help | Collect Logs and Diagnostic Data and upload them to https://uploads.jetbrains.com/, then provide its ID?
It would be great if you can upload your Dockerfile and docker-compose.yaml (you can remove private parts of the build process) to https://uploads.jetbrains.com/ as well. The project with docker-compose works for me if I'll change Go version from 1.13 to 1.17 in Dockerfile.