1

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

2
  • 1
    share your commands to run docker containers. to resolve your problem I should simulate you environment. Commented Mar 25, 2021 at 15:57
  • How do you run containers? docker-compose? Dockerfile? Both? Share us them. Commented Mar 25, 2021 at 16:11

1 Answer 1

1

The two container are not on the same network.

Possible solutions:

  • use docker-compose so that, by default, they are running within the same network
  • use docker run --network host mongo to use host network. Note: doesn't work with Docker Desktop for Win or Mac
  • manually attach the same network to both the container. After having launched mongo and the flask application, docker network connect network-name flask-container-name. You can retrieve the network name by inspecting the mongo container or docker network list
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.