admin管理员组文章数量:1123220
This is the docker-compose:
services:
backend:
container_name: backend
image: python:3.9-slim
working_dir: /app
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
volumes:
- ./api:/app
ports:
- "8000:8000"
networks:
- app-network
environment:
- MONGO_URI
- SECRET_KEY
- ALGORITHM
- TOKEN_EXPIRE_MINUTES
- ENCRYPTION_KEY
- MONGO_INITDB_DATABASE
env_file:
- .env
depends_on:
- mongo
build:
context: ./api
dockerfile: Dockerfile
mongo:
image: mongo:5.0
container_name: mongo
ports:
- "28000:27017"
volumes:
- ./mongo_data:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME
- MONGO_INITDB_ROOT_PASSWORD
env_file:
- .env
restart: always
networks:
app-network:
driver: bridge
And this is the .env:
PYTHONUNBUFFERED=1
MONGO_URI=mongodb://adminuser:123asdfAaJKIhj@mongo:27017/
SECRET_KEY=asdfSD980SDadsfhu
ALGORITHM=HS256
TOKEN_EXPIRE_MINUTES=30
ENCRYPTION_KEY=B3hFQk1CUnpKcGxFUVFvR1pDSXU2dGlqYjczZ3R0d0E=
MONGO_INITDB_ROOT_USERNAME=adminuser
MONGO_INITDB_ROOT_PASSWORD=123asdfAaJKIhj
MONGO_INITDB_DATABASE=scrapmind_db
When I try to connect to db container I recived the following error
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: scrapmindmongo:27017: [Errno -2] Name or service not known (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: 67813bd5f71ffae59e979903, topology_type: Unknown, servers: [<ServerDescription ('scrapmindmongo', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('scrapmindmongo:27017: [Errno -2] Name or service not known (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS:
20000.0ms)')
Also when I try to connect to mongodb://adminuser:123asdfAaJKIhj@localhost:28000/ using mongoDB Compass this returns Authentication failed. Mongo container it's up without errors. Any advice?
本文标签: mongodbHow to connect Mongo Container to another in DockerStack Overflow
版权声明:本文标题:mongodb - How to connect Mongo Container to another in Docker? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736557295a1944595.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论