This topic follows a discussion on this ticket
am using Couchbase java client SDK 2.7.7 and am running into a problem while trying to run automated integration tests. In such test we usually use random ports to be able to run the same thing on the same Jenkins slave (using docker for example).
But, with the client, we can specify many custom ports but not the 8092, 8093, 8094 and 8095.
The popular TestContainers modules mention as well that those port have to remain static in their Couchbase module: https://www.testcontainers.org/modules/databases/couchbase/
Apparently it is also possible to change those ports at the server level.
The docker image is ‘couchbase:community-5.1.1’
Internally the ports are the ones written above but externally they are random. At the client level you can set up bootstrapHttpDirectPort and bootstrapCarrierDirectPort but apparently the 8092 and 8093 ports are taken from the server-side (who does not know which port was assigned to him).
I would like to ask you whether it is possible to change those ports at the client level and, if not, to seriously consider adding that feature.
This problem will be much easier to solve in Couchbase 6.5 (beta is downloadable now). It will be the first version to officially support setting alternate addresses.
With this feature it will be possible to let Docker assign random (or fixed non-standard) ports for all services, then tell Couchbase about the port assignments so it can advertise the correct ports to a client running outside Docker.
Thank you for answering.
I understand but i don’t think that docker allows to have a random internal port.
We would have such a workflow:
- "8091" <= this is a fixed internal port with a random external port, otherwise it would be 8091:8091
1: Start the image
2: Inside the image parse the /var/run/docker.sock file to get the exposed port (lots of work and no easy way to do that)
3: Inject those ports into the couchbase server’s conf and start it
4: The client tries to connect to the the exposed port and… failure
Well, we would have this:
Exposed random port: 3485 (just an example)
Internal fix port: 8091
Internal couchbase port: 3485 (same as the exposed random port)
- 8091 <> 3485 so it would not work.
- Getting the random exposed ports from within the container is possible but not trivial.
As far as I know, it is not possible to have a random port for both external and internal ports in a docker-compose file. And even if it was the case, the image’s changes are not trivial compared to just having fixed ports at the client level for your integration tests.
I am opened to better ideas or any compromise.
Sorry, I didn’t explain this part well. The internal ports would be the fixed, standard ports. Docker would map them to random external ports. Then you’d execute the
couchbase-cli setting-alternate-address inside the Couchbase container to tell Couchbase about the external ports so it can advertise them to the client when the client connects. That’s the theory, anyway.
So Couchbase would still listen from the standard ports but advertise different ports to the clients?
That is what the documentation says… interresting feature.
Forces us to migrate to a newer version but i guess that with some work we can make it function.
A lot of trouble to avoid to pass ports at the client level though.
Thank you, we’ll probably try it.