最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

docker - TestContainers with RedPanda not coming up on exposing more than one port - Stack Overflow

programmeradmin2浏览0评论

I have the following working snippet when exposing port 9092 and launching RedPanda

    private GenericContainer<?> createRpContainer() {
        try (GenericContainer<?> rpContainer = new GenericContainer<>(DockerImageName.parse("docker.redpanda/redpandadata/redpanda:v23.1.10"))
                .withNetwork(network)
                .withExposedPorts(9092)
                //.withExposedPorts(8081, 9092)
                .withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
                        new HostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(9092), new ExposedPort(9092)))

                ))
//                .withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
//                        new HostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(8081), new ExposedPort(8081)))
//
//                ))

        ) {
            return rpContainer;
        }
    }

It is my understanding that schema registry also runs but at port 8081. The moment I uncomment the commented out lines, the container health-check fails with below error:

.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker.redpanda/redpandadata/redpanda:v23.1.10

    at .testcontainers.containers.GenericContainer.doStart(GenericContainer.java:351)
    at .testcontainers.containers.GenericContainer.start(GenericContainer.java:322)
    at com.example.gcsbpa.gcsbpa.GcsbpaApplicationTests.contextLoads(GcsbpaApplicationTests.java:82)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
Caused by: .rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
    at .rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
    at .testcontainers.containers.GenericContainer.doStart(GenericContainer.java:336)
    ... 5 more
Caused by: .testcontainers.containers.ContainerLaunchException: Could not create/start container
    at .testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:555)
    at .testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:346)
    at .rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
    ... 6 more
Caused by: .testcontainers.shaded.awaitility.core.ConditionTimeoutException: .testcontainers.containers.GenericContainer$$Lambda/0x00001ffe01865e88 expected the predicate to return <true> but it returned <false> for input of <InspectContainerResponse(args=[redpanda, start, --overprovisioned], config=ContainerConfig(attachStderr=false, attachStdin=false, attachStdout=false, cmd=[redpanda, start, --overprovisioned], domainName=, entrypoint=[/entrypoint.sh], env=[PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin, EDITOR=vi], exposedPorts=[8081/tcp, 8082/tcp, 9092/tcp, 9644/tcp], hostName=151031f63382, image=docker.redpanda/redpandadata/redpanda:v23.1.10, labels={.opencontainers.image.authors=Redpanda Data <[email protected]>, .testcontainers=true, .testcontainers.lang=java, .testcontainers.sessionId=c7a418bc-3fdd-4a19-8bcd-7c59a58ad149, .testcontainers.version=1.20.3}, macAddress=null, networkDisabled=null, onBuild=null, stdinOpen=false, portSpecs=null, stdInOnce=false, tty=false, user=redpanda, volumes={/var/lib/redpanda/data={}}, workingDir=, healthCheck=null), created=2024-11-16T02:28:25.872816597Z, driver=overlay2, execDriver=null, hostConfig=HostConfig(binds=[], blkioWeight=0, blkioWeightDevice=null, blkioDeviceReadBps=null, blkioDeviceWriteBps=null, blkioDeviceReadIOps=null, blkioDeviceWriteIOps=null, memorySwappiness=null, nanoCPUs=0, capAdd=null, capDrop=null, containerIDFile=, cpuPeriod=0, cpuRealtimePeriod=0, cpuRealtimeRuntime=0, cpuShares=0, cpuQuota=0, cpusetCpus=, cpusetMems=, devices=null, deviceCgroupRules=null, deviceRequests=null, diskQuota=null, dns=null, dnsOptions=null, dnsSearch=null, extraHosts=null, groupAdd=null, ipcMode=shareable, cgroup=, links=[], logConfig=LogConfig(type=json-file, config={}), lxcConf=null, memory=0, memorySwap=0, memoryReservation=0, kernelMemory=null, networkMode=default, oomKillDisable=null, init=null, autoRemove=false, oomScoreAdj=0, portBindings={8081/tcp=[Lcom.github.dockerjava.api.model.Ports$Binding;@2c7aba7c}, privileged=false, publishAllPorts=false, readonlyRootfs=false, restartPolicy=no, ulimits=null, cpuCount=0, cpuPercent=0, ioMaximumIOps=0, ioMaximumBandwidth=0, volumesFrom=null, mounts=null, pidMode=, isolation=null, securityOpts=null, storageOpt=null, cgroupParent=, volumeDriver=, shmSize=67108864, pidsLimit=null, runtime=runc, tmpFs=null, utSMode=, usernsMode=, sysctls=null, consoleSize=[0, 0], cgroupnsMode=private), hostnamePath=/var/lib/docker/containers/151031f63382ab65eac4e9a02af2e6458afb7edd3f7861f5ad7e6918cbdd7562/hostname, hostsPath=/var/lib/docker/containers/151031f63382ab65eac4e9a02af2e6458afb7edd3f7861f5ad7e6918cbdd7562/hosts, logPath=/var/lib/docker/containers/151031f63382ab65eac4e9a02af2e6458afb7edd3f7861f5ad7e6918cbdd7562/151031f63382ab65eac4e9a02af2e6458afb7edd3f7861f5ad7e6918cbdd7562-json.log, id=151031f63382ab65eac4e9a02af2e6458afb7edd3f7861f5ad7e6918cbdd7562, sizeRootFs=null, sizeRw=null, imageId=sha256:af23ebc269bd7fbc5eecee4536caf993501dddbfd1f630db507c45db33c7b0ae, mountLabel=, name=/serene_lamport, restartCount=0, networkSettings=NetworkSettings(bridge=, sandboxId=52eef42ce2abcb238fb9cdcb349dea09e43ea0119e398e2785f3ddf07ca3a5c5, hairpinMode=false, linkLocalIPv6Address=, linkLocalIPv6PrefixLen=0, ports={9092/tcp=null, 8081/tcp=[Lcom.github.dockerjava.api.model.Ports$Binding;@729c98, 9644/tcp=null, 8082/tcp=null}, sandboxKey=/var/run/docker/netns/52eef42ce2ab, secondaryIPAddresses=null, secondaryIPv6Addresses=null, endpointID=839ee5d923c1195d688be270aee104a691a67b061f186a0985eb5d4e5b34d2ea, gateway=172.17.0.1, portMapping=null, globalIPv6Address=, globalIPv6PrefixLen=0, ipAddress=172.17.0.3, ipPrefixLen=16, ipV6Gateway=, macAddress=02:42:ac:11:00:03, networks={bridge=ContainerNetwork(ipamConfig=null, links=[], aliases=null, networkID=07627434eb4f92bacfa4a0678f637a90717da37745ca3fcd3af7082224bc1d92, endpointId=839ee5d923c1195d688be270aee104a691a67b061f186a0985eb5d4e5b34d2ea, gateway=172.17.0.1, ipAddress=172.17.0.3, ipPrefixLen=16, ipV6Gateway=, globalIPv6Address=, globalIPv6PrefixLen=0, macAddress=02:42:ac:11:00:03)}), path=/entrypoint.sh, processLabel=, resolvConfPath=/var/lib/docker/containers/151031f63382ab65eac4e9a02af2e6458afb7edd3f7861f5ad7e6918cbdd7562/resolv.conf, execIds=null, state=InspectContainerResponse.ContainerState(status=running, running=true, paused=false, restarting=false, oomKilled=false, dead=false, pid=2616, exitCode=0, error=, startedAt=2024-11-16T02:28:25.981077764Z, finishedAt=0001-01-01T00:00:00Z, health=null), volumes=null, volumesRW=null, node=null, mounts=[InspectContainerResponse.Mount(name=ba922f946d759079668ecb15f9246a3ad44ce49d0505c49c19aa13d2bb827406, source=/var/lib/docker/volumes/ba922f946d759079668ecb15f9246a3ad44ce49d0505c49c19aa13d2bb827406/_data, destination=/var/lib/redpanda/data, driver=local, mode=, rw=true)], graphDriver=GraphDriver(name=overlay2, data=GraphData(rootDir=null, deviceId=null, deviceName=null, deviceSize=null, dir=null)), platform=linux)> within 5 seconds.
    at .testcontainers.shaded.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
    at .testcontainers.shaded.awaitility.core.AbstractHamcrestCondition.await(AbstractHamcrestCondition.java:86)
    at .testcontainers.shaded.awaitility.core.ConditionFactory.until(ConditionFactory.java:985)
    at .testcontainers.shaded.awaitility.core.ConditionFactory.until(ConditionFactory.java:691)
    at .testcontainers.shaded.awaitility.core.ConditionFactory.until(ConditionFactory.java:708)
    at .testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:458)
    ... 8 more

I also don't see the 2 ports exposed as I think they would have been when I try to expose both.

CONTAINER ID   IMAGE                                                COMMAND                  CREATED         STATUS         PORTS                                                  NAMES
151031f63382   docker.redpanda/redpandadata/redpanda:v23.1.10   "/entrypoint.sh redp…"   4 seconds ago   Up 3 seconds   8082/tcp, 9092/tcp, 0.0.0.0:8081->8081/tcp, 9644/tcp   serene_lamport
2803df66bd66   testcontainers/ryuk:0.9.0                            "/bin/ryuk"              4 seconds ago   Up 3 seconds   0.0.0.0:54236->8080/tcp                                testcontainers-ryuk-c7a418bc-3fdd-4a19-8bcd-7c59a58ad149
发布评论

评论列表(0)

  1. 暂无评论