skip to Main Content

I have a Spring Application that is making REST calls that is intercepted by Wiremock, running this setup on my local machine works well but when running dockerized I can see that the request reaches Wiremock but nothing comes back so from the application side it looks like the connection was refused. Where did the response go?

Stripped version of my docker-compose file:

version: "3.9"
services:
    test-service-application:
        build:
            context: .
            dockerfile: Dockerfile-local
        hostname: test-service
        privileged: true
        ports:
            - "22101:22101" # Application port
        environment:
            - "SPRING_PROFILES_ACTIVE=local"

    wiremock:
        image: 'wiremock/wiremock:2.32.0'
        container_name: 'wiremock'
        ports:
            - "8443:8080" # Web browser
            - "30121:8080" # Service #1
        environment:
            https-port: 8443
            http-port: 8443

And REST call:

WebClient webClient = WebClient.builder()
    .clientConnector(new ReactorClientHttpConnector(HttpClient.create()))
    .build();

webClient
    .method(HttpMethod.GET)
    .uri("http://localhost:30121/test-endpoint/")
    .contentType(MediaType.APPLICATION_JSON)
    .retrieve()
    .bodyToMono(MyClassDTO)
    .block();

2

Answers


  1. Chosen as BEST ANSWER

    After A LOT of googling I finally found the answer to my problem by using host.docker.internal as the DNS string instead of container name. This because using the container name it wouldn't route it correctly through the ports I wanted.


  2. That is because Docker actually can build an own internal network and docker-compose does this by default.
    The hostname inside of docker is the container name or -using docker-compose- the service name.
    In your app the correct request URL would be http://wiremock:30121/test-endpoint/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search