2 / 2
Jul 2024

Followed below steps:

  1. Create docker
    docker run -d -p 27017:27017 --name=mongodb -v data-mongodb:/data/db mongo:latest

  2. docker ps --format “{{.ID}}: {{.Names}}”

2c9750587438: mongodb 5a2235c4d8ff: kafka1 787678268f91: zoo1
  1. docker exec works fine.
    docker exec -it mongodb mongosh
    Current Mongosh Log ID:
669d460e704e58c860149f47 Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.10 Using MongoDB: 7.0.12 Using Mongosh: 2.2.10 For mongosh info see: https://docs.mongodb.com/mongodb-shell/
The server generated these startup warnings when booting 2024-07-21T17:04:51.689+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem 2024-07-21T17:04:52.012+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted 2024-07-21T17:04:52.013+00:00: Soft rlimits for open file descriptors too low

test>

  1. from pymongo
import MongoClient client = MongoClient('mongodb://127.0.0.1:27017/') client.list_database_names()

GIVES timeout error.

raise ServerSelectionTimeoutError( pymongo.errors.ServerSelectionTimeoutError: 127.0.0.1:27017: [Errno 104] Connection reset by peer (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: 669d447f24ef3e38dc949128, topology_type: Unknown, servers: [<ServerDescription ('127.0.0.1', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('127.0.0.1:27017: [Errno 104] Connection reset by peer (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)')>]>

Please help me resolve this issue.

Where is python being invoked from, another container? If so the two containers would need to be on the same docker network and the host in the connection string would be mongodb://mongodb

If python is being invoked on the host computer, it looks like it should work. But there could be some docker configuration or firewall that needs updating.