docker-compose-buildkite-plugin
docker-compose-buildkite-plugin copied to clipboard
How to set a persistent, resolvable hostname for the started container?
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...
As stated, I can live with the static IP solution, so feel free to close the issue if you think it is invalid.
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 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
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: .