Bind multiple ip address to a host

How to bind multiple IPs to a custom hostname?
Tried with “extra_hosts” but it doesn’t work on docker deployed on linux. It works on docker desktop (windows).
Can someone suggest a better solution?

This command

docker run --rm -it --add-host myhost:127.0.0.1 --add-host myhost:127.0.0.2 bash cat /etc/hosts | grep myhost

gives me the following output on Linux:

127.0.0.1	myhost
127.0.0.2	myhost

And compose file

services:
  bash:
    image: bash
    extra_hosts:
      - myhost:127.0.0.1
      - myhost:127.0.0.2
    command:
     - sh
     - -c
     - |
       cat /etc/hosts | grep myhost

and this command gives me the same:

docker compose up
[+] Running 2/0
 ✔ Network hosts_default   Created                                                                0.0s
 ✔ Container hosts-bash-1  Created                                                                0.0s
Attaching to bash-1
bash-1  | 127.0.0.1	myhost
bash-1  | 127.0.0.2	myhost
bash-1 exited with code 0
1 Like