Skip to content
Advertisement

Python Mongo docker-compose Topology Error

I’m trying really simple example of mongo with python and got an error.

Dockerfile:

JavaScript

run_test.sh

JavaScript

docker-compose.yaml:

JavaScript

db_test.py:

JavaScript

db.py:

JavaScript

I’m doing docker-compose up and got this output:

JavaScript

So it looks like it can’t connect to the database. I didn’t change ports or something, and another example works like a charm with those settings, so I don’t really know what I’m missing. Without docker, it works fine.

Advertisement

Answer

Solved by adding container_name to db service in docker-compose, and then using it name as host when connecting to in python code.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement