Debug via Makefile


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
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:



You can attach the debugger to a process inside the Docker container, please see

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:

- seccomp:unconfined

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:

The port should be the same as specified in your docker-compose file, e.g. please see 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?



So I added necessary permissions and port 40000 in my docker-compose file

Have you added dlv debugger command execution as well? Please see 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:

- "seccomp:unconfined"
entrypoint: ${ENTRY}
- 80
- 9100
- "20130:80"
- "20131:9100"
- "40000:40000"
command: /dlv --headless --listen=:40000 --api-version=2 exec /server

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, 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 as well. The project with docker-compose works for me if I'll change Go version from 1.13 to 1.17 in Dockerfile.


Please sign in to leave a comment.