testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

getContainerByServiceName expects an instance name

Open aruiz14 opened this issue 4 years ago • 1 comments

#2314 brought support for selecting a container based on the service name when using docker-compose (thanks 🙌 !). However, the value it expects contains the "container number" (e.g. service_1), instead of just the service name, e.g. just service.

This does not match the behaviour of using docker-compose directly:

$ docker-compose ps agent
      Name             Command       State   Ports
--------------------------------------------------
myapp_agent_1   /bin/k3s agent   Up
$ docker-compose ps agent_1
ERROR: No such service: agent_1

According to this test, it looks like the expected behavior, or maybe was incorrectly modeled.

Maybe using getServiceInstanceName from getContainerByServiceName would provide compatibility for both cases?

aruiz14 avatar Jul 13 '21 07:07 aruiz14

I got hit by the same problem. To solve this I had to clone the private method getServiceInstanceName(String serviceName) to get the service instance name for a service name. I have no idea how I can get the service instance name in any other way.

getServicePort() calls getServinceInstanceName in internally and therefore it works with both.

mjh-c avatar Jun 23 '22 09:06 mjh-c