How to connect springboot docker container replica via docker swarm cluster which need to connected to mongo replicas which is mentioned in etc/hosts

I have configured 3 mongo DB replica in 3 VM and added mongo DB instances name in etc/hosts of each VM. Now i need to connect my spring boot docker container via docker swarm cluster since its needed to read etc/hosts of each VM how would i mention its in docker since I am new to docker .All docker replica and mongo DB replica runs in same network please advice

etc/hosts file

# mongo-1a mongo-1b mongo-1c

another ip for docker swarm manger node manager node


all this ip is mentioned in each of the servers

i have tried to add –host host:ip in docker create service but it fialed

Source: StackOverflow