admin管理员组

文章数量:1126346

I have a spring boot integration test using kafka testcontainer(v1.19.8). The test runs fine in local environment. In contrast, when running in Gitlab CI pipeline the test fails with the following error:

Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: advertised.listeners cannot use the nonroutable meta-address 0.0.0.0. Use a routable IP address.

My Gitlab CI job looks like the following:

# DinD service is required for Testcontainers
services:
  - name: docker:dind
    # explicitly disable tls to avoid docker startup interruption
    command: ["--tls=false"]

variables:
  # Instruct Testcontainers to use the daemon of DinD, use port 2375 for non-tls connections.
  DOCKER_HOST: "tcp://docker:2375"
  # Instruct Docker not to start over TLS.
  DOCKER_TLS_CERTDIR: ""
  # Improve performance with overlayfs.
  DOCKER_DRIVER: overlay2

test:
 image: gradle:5.0
 stage: test
 script: ./gradlew test

I didn't set KAFKA_ADVERTISED_LISTENERS for my test container as I don't know the mapped port in advance. The mapped port is only available after I start the testcontainer and after started, the addEnv() method on the KafkaContainer is not usable to redefine the value of advertised listeners.

Questions:

  1. Is there anything I can change in gitlab-ci job configuration so that kafka testcontainer stops using 0.0.0.0 in KAFKA_ADVERTISED_LISTENERS ?

  2. Is there any solution using KafkaContainer or I have to switch to FixedHostPortGenericContainer(although I don't like the idea of a fixed port and the constructor of FixedHostPortGenericContainer is deprecated) ?

本文标签: dockerKafka TestContainer advertised listeners configuration when using DinDStack Overflow