dockerdocker-composedocker-networkbridge

Docker-Compose containers cannot make http request themselves


I have 3 containers and the main container - con_a - should make requests to others. When con_a makes an HTTP request, the other container's response is "502 Timeout". The details of containers and requests are below. When I try to make a request with curl in the console, there is no problem and the request is working.

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

The request in the con_a

response = requests.get("http://con_c:1337/health_check")

The request is normally just return "success".

The response

'<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'

Solution

  • Python request problem

    I thought the problem is about the docker networking problem, but the problem was python's automation. The request contains more settings than my settings and before the get request, I add a trust environment settings like the other post. I found the solution in this post: python request problem