dockerflask-mongoengine

I have mongo db in a docker container and I want to connect my app which is running on another container


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',)>]>"


Solution

  • The two container are not on the same network.

    Possible solutions: