I'm scaling up several Redis containers using Docker compose and want to find a way to get all of the IP addresses that correspond to a specific hostname in bash. I've got 5 Redis containers up, and all of them have the hostname redis
. I tried the command getent hosts redis | awk '{ print $1 }'
to hopefully get all of the IP addresses of the redis Docker images, but every time it would return only one of them. Example output of running the command without awk inside one of the Redis containers a few times is below:
bash-4.4# getent hosts redis
172.16.0.7 redis redis
bash-4.4# getent hosts redis
172.16.0.6 redis redis
bash-4.4# getent hosts redis
172.16.0.5 redis redis
bash-4.4# getent hosts redis
172.16.0.6 redis redis
I want a way to get all of the IP addresses in one command. Does anyone know how to do that in bash?
Edit: My question is different because I'm not trying to get the IP address of the host, I'm trying to get all of the IP addresses that match the hostname by running a bash script inside the container myself.