How to get service IP in a dynamic fashion while starting using docker-compose. How to get the IP of service-a
which is used as a configuration parameter while starting up docker-compose.yaml
service-a:
service-b:
depends_on:
service-a
How to get service IP in a dynamic fashion while starting using docker-compose. How to get the IP of service-a
which is used as a configuration parameter while starting up docker-compose.yaml
service-a:
service-b:
depends_on:
service-a
The recommended way is not to use the IP address in docker-compose but use the service name instead. If you still want an IP for some reason then you can either set Static IP with your container (not recommended) Link: https://stackoverflow.com/a/45420160/970422
Or you get IP by using docker inspect
commands. More details on this approach is mentioned here: https://www.freecodecamp.org/news/how-to-get-a-docker-container-ip-address-explained-with-examples/
Examples:
docker exec container-name cat /etc/hosts
docker exec -it container-name /bin/bash
ip -4 -o address
docker network inspect -f \
'{{json .Containers}}' 9f6bc3c15568 | \
jq '.[] | .Name + ":" + .IPv4Address'