Debugging Dapr Apps running in Docker Compose

Debug Dapr apps locally which are part of a Docker Compose deployment

The goal of this article is to demonstrate a way to debug one or more daprised applications (via your IDE, locally) while remaining integrated with the other applications that have deployed in the docker compose environment.

Let’s take the minimal example of a docker compose file which contains just two services :

  • nodeapp - your app
  • nodeapp-dapr - the dapr sidecar process to your nodeapp service

compose.yml

  1. services:
  2. nodeapp:
  3. build: ./node
  4. ports:
  5. - "50001:50001"
  6. networks:
  7. - hello-dapr
  8. nodeapp-dapr:
  9. image: "daprio/daprd:edge"
  10. command: [
  11. "./daprd",
  12. "--app-id", "nodeapp",
  13. "--app-port", "3000",
  14. "--resources-path", "./components"
  15. ]
  16. volumes:
  17. - "./components/:/components"
  18. depends_on:
  19. - nodeapp
  20. network_mode: "service:nodeapp"
  21. networks:
  22. hello-dapr

When you run this docker file with docker compose -f compose.yml up this will deploy to Docker and run as normal.

But how do we debug the nodeapp while still integrated to the running dapr sidecar process, and anything else that you may have deployed via the Docker compose file?

Lets start by introducing a second docker compose file called compose.debug.yml. This second compose file will augment with the first compose file when the up command is ran.

compose.debug.yml

  1. services:
  2. nodeapp: # Isolate the nodeapp by removing its ports and taking it off the network
  3. ports: !reset []
  4. networks: !reset
  5. - ""
  6. nodeapp-dapr:
  7. command: ["./daprd",
  8. "--app-id", "nodeapp",
  9. "--app-port", "8080", # This must match the port that your app is exposed on when debugging in the IDE
  10. "--resources-path", "./components",
  11. "--app-channel-address", "host.docker.internal"] # Make the sidecar look on the host for the App Channel
  12. network_mode: !reset "" # Reset the network_mode...
  13. networks: # ... so that the sidecar can go into the normal network
  14. - hello-dapr
  15. ports:
  16. - "3500:3500" # Expose the HTTP port to the host
  17. - "50001:50001" # Expose the GRPC port to the host (Dapr Worfklows depends upon the GRPC channel)

Next, ensure that your nodeapp is running/debugging in your IDE of choice, and is exposed on the same port that you specifed above in the compose.debug.yml - In the example above this is set to port 8080.

Next, stop any existing compose sessions you may have started, and run the following command to run both docker compose files combined together :

docker compose -f compose.yml -f compose.debug.yml up

You should now find that the dapr sidecar and your debugging app will have bi-directional communication with each other as if they were running together as normal in the Docker compose environment.

Note : It’s important to highlight that the nodeapp service in the docker compose environment is actually still running, however it has been removed from the docker network so it is effectively orphaned as nothing can communicate to it.

Demo : Watch this video on how to debug local Dapr apps with Docker Compose

Last modified October 11, 2024: Fixed typo (#4389) (fe17926)