Trouble to MongoDB Single Node Replica Set in Docker Container

I am trying to run MongoDB in a Docker container and apply a Single Node Replica Set in an Oracle Cloud Ubuntu environment without using docker-compose.

When I execute rs.initiate() in mongosh, members are automatically created with the container's ID (/etc/hosts). However, when trying to connect externally using Compass, I get the error message "getaddrinfo ENOTFOUND $CONTAINER_ID" and cannot establish a connection.

I have tried changing the host information in rs.initiate() arguments to 'localhost', '127.0.0.1', and external IP, but none of them work. I have also tried changing Docker's ports, but the issue persists.

Currently, only port 27017 is open in the cloud, and it functions properly.

I am seeking assistance in identifying the problem.

Just in case, I'm adding my options (nothing special)

In Dockerfile

mongod --bind_ip_all --replSet rs --port 27017

Container Execution

docker run -d \
  -p 27017:27017\
  --name $NAME \
  -v $VOLUME_DIR:/data/db \
  $IMAGE_NAME

Attempted Replica Set with IP or ID expected to connect, but failed. I hope to be connected to the Replica Set(single node, primaey only).



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Object oriented programming concepts (OOPs)

Network Error and Timeout on Authorize.net JS