How can I connect to a MongoDB replica set cluster created with Docker using Compass?

I have followed everything in the relevant document. All my outputs are correct as in the document, but I encounter an error when trying to establish a connection through the Compass GUI or with a framework like Node.js.

Here is the mongodb documentation

The connection string I used for Compass:


The error I received in the Compass interface:

getaddrinfo ENOTFOUND mongo2

Could you guide me on how to resolve this issue?

When the docker cluster is up and running, what do you get when you run the command the following commands:

docker ps
ping mongo2