[英]Timeout error connecting to Atlas mongoDB from a container
My application can connect to my Atlas mongodb when I run it on local without a container.当我在没有容器的本地运行它时,我的应用程序可以连接到我的 Atlas mongodb。
When I put my application in a container I am unable to access the Atlas mongodb.当我将应用程序放入容器时,我无法访问 Atlas mongodb。
I have whitelisted all IP's.我已将所有 IP 列入白名单。
self.myclient = pymongo.MongoClient(mongodb+srv://admin:<password>@mongodbscrapperconf-lctzq.gcp.mongodb.net/test?retryWrites=true&w=majority&ssl=true&authSource=admin)
I have tried both to connect to my Atlas database on local with my container and running my container in GCP.我已经尝试使用我的容器连接到本地的 Atlas 数据库并在 GCP 中运行我的容器。 In both cases I am getting a timeout error from mongoDB.
在这两种情况下,我都收到来自 mongoDB 的超时错误。
My DockerFile is looking like我的 DockerFile 看起来像
FROM python:3.7
COPY . /app
WORKDIR /app
RUN apt-get update && apt-get install ca-certificates && rm -rf /var/cache/apk/*
COPY ./host.crt /usr/local/share/ca-certificates
RUN update-ca-certificates
RUN pip install -r requirements.txt
EXPOSE 8000
CMD python ./controller.py cloud
requirements.txt要求.txt
iso4217
validators
pymongo
pymongo[srv]
flask
lxml
flask-cors
configparser
UPDATED: I found out that the connection is encrypted and the connection need to accept SSL certificates.更新:我发现连接是加密的,连接需要接受 SSL 证书。 I have tried this but Atlas is still refusing the connection.
我已经尝试过了,但 Atlas 仍然拒绝连接。
I think you need also to add pyopenssl
to your requirments.txt
我认为您还需要将
pyopenssl
添加到您的requirments.txt
I solve the issue by adding我通过添加解决了这个问题
pymongo[tls,srv]
To the requirements.txt到 requirements.txt
This is the resulting requirements.txt这是生成的 requirements.txt
iso4217
validators
pymongo[tls,srv]
flask
lxml
flask-cors
configparser
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.