Home > Back-end >  Debug a service defined in docker-compose.yml
Debug a service defined in docker-compose.yml

Time:10-13

I'm trying to enable remote debugging for one of the services included in my integration test. Most of the tests work fine, however if a test fails it is difficult to debug one of the other services. The (simplified) structure of the integration test is as follows:

Service A (service under test) -> GraphQL service -> Stubbed REST services

I'm using the following setup:

Service A docker-compose.yml

version: '3.5'

services:
  rest-stubs:
    image: rest-stubs:1.2.3
    container_name: rest-stubs
    ports:
      - "8082:8080"

  graphql-service:
    image: graphql-service:1.2.3
    container_name: graphql-service
    ports:
      - "8083:8080"
      - "5005:5005"
    environment:
      - some.stub-url=http://rest-stubs:8080/some-stub-url

Dockerfile of graphql-service:

FROM graphql-service

EXPOSE 8080 8080
EXPOSE 5005 5005

ADD app/target/service-*-exec.jar /app/spring-boot-service.jar

CMD ["-java -agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=n \
            -jar /app/spring-boot-service.jar"]

When I perform the integration test located in service A, the services defined in the docker-compose.yml spin up. I would have expected to be able to connect to the graphQL service' remote debugging port on 5005, however I receive a Unable to open debugger port (localhost:5005): java.net.ConnectException "Connection refused (Connection refused) exception.

Does anyone know how I can properly remote debug a docker service?

CodePudding user response:

EXPOSE will only expose to others containers that are linked, such as other services in the network without publishing the port to the host machine.

You need to be publish it like this:

version: '3.5'

services:
  rest-stubs:
    image: rest-stubs:1.2.3
    container_name: rest-stubs
    ports:
      - "8082:8080"

  graphql-service:
    image: graphql-service:1.2.3
    container_name: graphql-service
    ports:
      - "8083:8080"
      - "5005:5005"
    environment:
      - some.stub-url=http://rest-stubs:8080/some-stub-url

CodePudding user response:

Found the answer; I tried to connect to the container by using localhost:5005 settings in the IntelliJ remote debugger instead of the container's IP address.

I have obtained the IP address of the container using the answer in this post and used that IP address in Intellij's remote debugger dialog to connect instead.

  • Related