我有3个容器,主容器- con_a -应该向其他容器发出请求。当con_a发出HTTP请求时,另一个容器的响应是"502超时"。容器和请求的详细信息如下。当我尝试在控制台中使用curl发出请求时,没有问题并且请求正在工作。
Docker-compose.yml
version: "3"
services:
con_a:
networks:
- my_net
con_b:
container_name: con_b
hostname: con_b
ports:
- "9200:9200"
- "9300:9300"
networks:
- my_net
con_c:
container_name: con_c
image: con_c
hostname: con_c
build: ./con_c
ports:
- "1337:1337"
networks:
- my_net
networks:
my_net:
driver: bridge
con_a
中的请求response = requests.get("http://con_c:1337/health_check")
请求通常只是返回"success"
'<HEAD><TITLE>Connection timed out</TITLE></HEAD>n<BODY BGCOLOR="white" FGCOLOR="black"><H1>Connection timed out</H1><HR>n<FONT FACE="Helvetica,Arial"><B>nDescription: Connection timed out</B></FONT>n<HR>n<!-- default "Connection timed out" response (502) -->n</BODY>n'
'<HEAD><TITLE>Connection timed out</TITLE></HEAD>n<BODY BGCOLOR="white" FGCOLOR="black"><H1>Connection timed out</H1><HR>n<FONT FACE="Helvetica,Arial"><B>nDescription: Connection timed out</B></FONT>n<HR>n<!-- default "Connection timed out" response (502) -->n</BODY>n'
Python请求问题
我认为问题是关于docker的网络问题,但问题是python的自动化。请求包含的设置比我的设置更多,在get请求之前,我添加了一个信任环境设置,就像另一个帖子一样。我在这篇文章中找到了解决方案:python请求问题