我正在尝试使用docker-composer使用mongodb服务器启动python应用程序,但是我收到以下错误:
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
我真的不明白我的设置中缺少什么:
version: '3.6'
services:
web:
build: .
ports:
- "5000:5000"
- "9000:9000"
links:
- db
db:
image: mongo:latest
container_name: "mongodb"
ports:
- 27017:27017
command: mongod --smallfiles # --quiet
redis:
image: "redis:alpine"
我不知道为什么我无法连接到似乎已启动的服务器(docker ps
):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fb5a00bb8867 composedir_web "python app.py" 20 seconds ago Up 19 seconds 0.0.0.0:5000->5000/tcp, 0.0.0.0:9000->9000/tcp composedir_web_1
56aeae245ad5 mongo:latest "docker-entrypoint.s…" 14 minutes ago Up 20 seconds 0.0.0.0:27017->27017/tcp mongodb
51c64650bab8 redis:alpine "docker-entrypoint.s…" 14 minutes ago Up 21 seconds 6379/tcp composedir_red
答案 0 :(得分:1)
您需要配置python应用程序以在db:27017
而不是localhost:27017
上连接mongo