0

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?

Michiel
  • 2,914
  • 1
  • 18
  • 27
  • 1
    You must expose port 5005 in the docker-compose.yml – Ari0nhh Oct 12 '21 at 11:58
  • Thanks for your help, I originally had added the port but I guess I accidentally removed it while creating the snippet. I've updated my original post and added the 5005 port. – Michiel Oct 12 '21 at 13:07

2 Answers2

1

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
jeanpic
  • 481
  • 3
  • 15
  • Thanks for your help, I originally had added the port but I guess I accidentally removed it while creating the snippet. I've updated my original post and added the 5005 port. – Michiel Oct 12 '21 at 13:07
0

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.

Michiel
  • 2,914
  • 1
  • 18
  • 27