I used flask_mongoengine to connect to the db as follows:
app.config['MONGODB_SETTINGS'] = {
'host': 'mongodb://mongo:27017/db_name'
}
mongo is the name of the container, but i am getting the following error:
"pymongo.errors.ServerSelectionTimeoutError: mongo:27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: <TopologyDescription id: 605cb104a9a518d390b9ba99, topology_type: Single, servers: [<ServerDescription ('mongo', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongo:27017: [Errno -2] Name or service not known',)>]>"
The two container are not on the same network.
Possible solutions:
docker-compose
so that, by default, they are running within the same networkdocker run --network host mongo
to use host network. Note: doesn't work with Docker Desktop for Win or Macdocker network connect network-name flask-container-name
. You can retrieve the network name by inspecting the mongo container or docker network list