So, I didn't find a solution on YDB side, but looks like it is possible to configure testContainers.
Next configuration saved me:
private static final GenericContainer<?> ydbContainer = new GenericContainer<>(
DockerImageName.parse("cr.yandex/yc/yandex-docker-local-ydb:latest"))
.withCreateContainerCmdModifier(cmd -> {
HostConfig hostConfig = cmd.getHostConfig();
hostConfig.withPortBindings(
new PortBinding(
Ports.Binding.bindPort(grpcPort),
new ExposedPort(grpcPort)
)
);
cmd.withHostConfig(hostConfig);
})
.withExposedPorts(grpcPort)
.withCreateContainerCmdModifier(cmd -> cmd.withHostName("localhost"))
.withExtraHost("ydb-node", "127.0.0.1")
.withEnv("GRPC_PORT", String.valueOf(grpcPort))
.withEnv("YDB_USE_IN_MEMORY_PDISKS", "1");
we define some available grpcPort and bind all internal hostnames to localhost. Also, we set YDB GRPC_PORT to available grpc port on our machine. This way all discovered nodes will have host localhost and port - grpcPort.
It is not the solution I want, but it is workaround