0

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'
utul
  • 13
  • 5
  • The compose itself seems okay. Since you mention that the application works externally, it could be a problem with the containers unable to reach each other through the Docker network hostname feature. Try getting the IP address of the container you want to reach, and using that IP address directly, and see if that makes a change. – Marc Sances Jan 17 '23 at 08:35
  • I suppose you are using Gitlab, so we ask you to check on which IP address you bound Gitlab. – Antonio Petricca Jan 17 '23 at 09:11
  • Can you reach `con_c` from outside Docker via `http://localhost:1337`? If that doesn't work either, it suggests a configuration problem inside the `con_c` image. (Is the main container process actually set to listen to `0.0.0.0:1337`?) – David Maze Jan 17 '23 at 11:05

1 Answers1

0

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

utul
  • 13
  • 5