docker-compose-buildkite-plugin icon indicating copy to clipboard operation
docker-compose-buildkite-plugin copied to clipboard

How to set a persistent, resolvable hostname for the started container?

Open scream314 opened this issue 4 years ago • 3 comments

I have an integration test step using the docker-compose-buildkite-plugin. In this step I have to start the app container (run: app), and do some operations in it, start an app, and tear it down. The problem is, one of the other containers (tester) has to connect to this app container, but I cannot reference it as app, as Docker's DNS cannot resolve this name. No matter what I try in my Composefile (container_name: app, hostname: app, networks: mynet: aliases: - app...), tester is not able to resolve the name "app", only the name in the NAMES column of the output of docker ps is resolved to the app container's IP.

Is there a way to set a persistent, deterministic, resolvable hostname for the container started with run:?

Note: Currently I am creating a bridged network with ipam: config: set, and assigning a static IP to app, so I can reference it with this static IP from tester and it is working fine. If there is no easy way to use a hostname, I can live with this, too...

scream314 avatar May 28 '20 11:05 scream314

As stated, I can live with the static IP solution, so feel free to close the issue if you think it is invalid.

scream314 avatar Sep 03 '20 08:09 scream314

Hey @scream314 did you end up solving this? i'm having the same issue trying to get selenium grid service containers to be able to connect to the app container to run browser tests against the app host.

ryansdwilson avatar Jun 03 '21 03:06 ryansdwilson

@ryansdwilson I am not completely sure anymore what was my final solution, but iirc creating an explicit bridge and using static IPs (see the "Note" section in my first post), and referencing the containers by their IP address worked. See: https://docs.docker.com/compose/compose-file/compose-file-v3/#ipv4_address-ipv6_address

scream314 avatar Jun 09 '21 06:06 scream314

So sorry for the delay in getting back to you :(

All documentation on the matter would indicate that all services defined in docker compose will be able connect to other containers just using the service name of those services in the same network. Even the official selenium hub docker compose configuration does that!

If that wasn't working for you we would definitely need more information to continue to troubleshoot. Unfortunately, based on your comment from a year ago I don't think that this is an issue any more (that you care about at least) so I will be closing it :disappointed: .

toote avatar Sep 22 '22 03:09 toote