我在 docker 中运行 Python Falcon 应用程序。我试图在将其部署到弹性 beantalk 之前在本地工作。当我尝试连接在另一个 Docker 中运行的本地 DynamoDB 时,出现以下错误。hayirlisi_test | Traceback (most recent call last):hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_connhayirlisi_test | (self._dns_host, self.port), self.timeout, **extra_kw)hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connectionhayirlisi_test | raise errhayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connectionhayirlisi_test | sock.connect(sa)hayirlisi_test | ConnectionRefusedError: [Errno 111] Connection refusedhayirlisi_test |hayirlisi_test | During handling of the above exception, another exception occurred:hayirlisi_test |hayirlisi_test | Traceback (most recent call last):hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/httpsession.py", line 258, in sendhayirlisi_test | decode_content=False,hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopenhayirlisi_test | _stacktrace=sys.exc_info()[2])hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 343, in incrementhayirlisi_test | raise six.reraise(type(error), error, _stacktrace)hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 686, in reraise我的 DynamoDB 变量声明如下所示dynamodb = boto3.client('dynamodb', aws_access_key_id="anything",aws_secret_access_key="anything",region_name="local",endpoint_url="http://127.0.0.1:8000/%22)我也尝试使用“-sharedDB”参数运行 DynamoDB docker。但是,我无法弄清楚我做错了什么
1 回答
青春有我
TA贡献1784条经验 获得超8个赞
如果你在两个 docker 容器中运行它,有一些事情需要发生。首先,localhost
是容器本地的。也就是说,您正在调用容器的本地主机,而不是您机器的本地主机。
您需要使其他容器彼此可见。这可以通过networks
. 所以,你需要这样设置:
docker network create test_network
然后你可以像这样在那个网络上运行你的容器:
docker run -p <host>:<container> --network=test_network -n <container_name> <image>
现在容器中的 url 将是name
您设置的容器的 url :
myendpoint = 'http://<container_name>:<container_port>'
要查看该网络上的容器,您可以运行
docker network inspect test_network
并查看该containers
部分。您将看到名称、IP 地址等。您要为容器命名的原因是因为除非您指定名称,否则名称是随机的,并且与尝试通过 ip 地址查找容器相比,这对您没有好处
添加回答
举报
0/150
提交
取消