Testcontainers 似乎无法通信 – 连接被拒绝

huangapple go评论57阅读模式
英文:

Testcontainers cant seem to communicate - connection refused

问题

所以,我有一个容器设置如下:

genericContainer
    .withImagePullPolicy(PullPolicy.alwaysPull())
    .withExposedPorts(SPRING_BOOT_PORT)
    .withNetwork(NETWORK)
    .withAccessToHost(true);

这个容器启动正常,我可以ping它。

我还有另一个容器:

S3MockContainer(DockerImageName.parse("adobe/s3mock:2.4.13"))
    .withInitialBuckets(S3_BUCKET_NAME)
    .withNetwork(NETWORK);

但我似乎无法从我的第一个测试容器内部连接或ping S3Mock容器。我已经尝试传递 s3MockContainer.getHost() + getFirstMappedPort(),但它似乎无法连接。

英文:

so i have one container set up like

genericContainer
                    .withImagePullPolicy(PullPolicy.alwaysPull())
                    .withExposedPorts(SPRING_BOOT_PORT)
                    .withNetwork(NETWORK)
                    .withAccessToHost(true);

this starts up fine and i can ping it.

I have another container

S3MockContainer(DockerImageName.parse("adobe/s3mock:2.4.13"))
            .withInitialBuckets(S3_BUCKET_NAME)
            .withNetwork(NETWORK);

I cant seem to connect or ping the s3Mock container from within my first test container. I have tried passing in the s3MockContainer.gethost() + getFirstMappedPort()

but it just is not able to connect?

答案1

得分: 1

Both containers are in the same network. So, in that case, you can use the real ports.

First, update S3MockContainer by adding withNetworkAliases("s3"), then you can use s3:9090 in your spring boot app in order to connect to.

Also, I don't think you need withAccessToHost(true).

英文:

Both containers are in the same network. So, in that case, you can use the real ports.

First, update S3MockContainer by adding withNetworkAliases("s3"), then you can use s3:9090 in your spring boot app in order to connect to.

Also, I don't think you need withAccessToHost(true).

huangapple
  • 本文由 发表于 2023年3月4日 03:27:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75631154.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定