Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Containers communication with python requests

Here is my architecture :

I have two containers (A and B) running on the same host with their own network.

docker-compose :

version : '3'
services: 

  A: 
    build: ./docker_A
    ports: 
      - "8090:8090"
    networks:
      - my_network

  B:
    build: ./docker_B
    ports: 
      - "8070:8070"    
    networks:
      - my_network

networks: 
  my_network:
    driver : bridge

Container b is running a bottle server :

@get('/')
def hello():
    return {"say":"Hello world"}

run(host='0.0.0.0', port=8070, debug=True)

docker inspect package_name_my_network returns :

{
        "Name": "package_name_my_network",
        "Id": "...",
        "Created": "...",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "...": {
                "Name": "package_name_A",
                "EndpointID": "...",
                "MacAddress": "...",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            },
            "...": {
                "Name": "package_name_B",
                "EndpointID": "...",
                "MacAddress": "...",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }

I'm trying to do a GET request from A :

ret = requests.get('http://172.18.0.2:8070/')

But each time I get this response : <Response [503]> / Network Error (tcp_error)

I tried several things :

Changed 172.18.0.2 to :

  • B : KO
  • name_package_B : KO
  • 0.0.0.0 : KO

From host machine :

curl -X GET http://172.18.0.2:8070/ : {"say":"Hello world"}

From A : docker exec -t -i package_name_A /bin/bash : I can ping :

  • 172.18.0.2
  • B
  • package_name_B

If someone has a solution, it would be wonderful.

Thanks for your time.

EDIT :

It's a proxy problem. If I do unset https_proxy and unset http_proxy, I'm able to reach B with A. The problem is, I can't reach the server on the host (not a container) anymore. Even with EXPORT no_proxy=172.0.0.0 Any Idea ?

like image 229
Polemon Avatar asked Apr 26 '18 09:04

Polemon


1 Answers

Solved : It was a proxy problem. I'm using session without env var :

session = requests.Session()
session.trust_env = False
ret = session.get(url, json=my_json)
like image 76
Polemon Avatar answered Sep 16 '22 15:09

Polemon