![](/img/trans.png)
[英]Docker container not able to call another running docker container from localhost?
[英]I am not able to call rest api which is in another container running at localhost:9090, using localstack 12.5 lambda (running at 4566 port)
用於 lambda 處理程序的 dummy.py 文件
import sys
import requests
def handler(event, context):
print("Inside handler")
x = requests.get('http://localhost:9090/ping')
print(x.status_code)
return str(x.content)
在處理程序中,當我調用另一個容器中的 get api 時,我收到連接被拒絕的錯誤。
錯誤:"ConnectionError","errorMessage":"HTTPConnectionPool(host='localhost', port=9090): Max retries exceeded with url: Caused by NewConnectionError('\
但是通過郵遞員,我可以訪問 http://localhost:9090/ping API
另外,如果我替換 x = requests.get('https://w3schools.com') 那么我得到 200 。
該問題已通過在 localstack 中添加以下 env 變量解決
LAMBDA_DOCKER_NETWORK="主機"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.