'Docker Container with 4 Nodes, No connection could be established using urllib3
I'm setting up a docker container which generates 4 nodes that will execute two python scripts: blockchain and import. More details below:
Docker File:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python3 python3-pip python3-dev build-essential
RUN mkdir /myApp
WORKDIR /myApp
COPY blockchain/requirements.txt /myApp/
RUN pip3 install -r requirements.txt
COPY blockchain/blockchain.py /myApp/
ENTRYPOINT ["python3"]
CMD ["blockchain.py"]
Docker Compose (docker-compose.yml):
version: '3'
services:
node1:
build: .
hostname: node1
ports:
- "5001:5000"
node2:
build: .
hostname: node2
ports:
- "5002:5000"
node3:
build: .
hostname: node3
ports:
- "5003:5000"
node4:
build: .
hostname: node4
ports:
- "5004:5000"
This means that I want to create 4nodes, and on the import script I will need to connect to this nodes using POST method. In the variable localIP I used my local @IP :
#I've tried to get the @ using Python
localIP = socket.gethostbyname(hostname)
#I've also used windows CMD: ipconfig to get the @IP
#localIP = '192.168.XX.XX'
#I've also tried the @IP we can get from google: what is my IP address
#localIP = '196.12X.XX.XX'
hosts = [
'https://'+localIP+':5001',
'https://'+localIP+':5002',
'https://'+localIP+':5003',
'https://'+localIP+':5004'
]
http = urllib3.PoolManager()
# register nodes - for each node, don't add itself the list
for host in hosts:
data = { "nodes": [x for x in hosts if x != host] }
data= json.dumps(data).encode('utf-8')
res = http.request('POST', host, body=data, headers={'Content-Type': 'application/json'})
But I get the following error:
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.XX.XX', port=5001): Max retries exceeded with url:
/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001FB210ACBB0>: Failed to establish
a new connection: [WinError 10061] No connection could be established because the target computer expressly refused it'))
When I try get from terminal the @IP of the nodes it returns blank value:
docker inspect -f '{{ .NetworkSettings.IPAddress }}' NODE-01-ID
The question is, Is the IP address wrong ? How can we provide the right IP address ?
Thank you
Solution 1:[1]
The problem is that you're putting the IP address explicitly and this @ is dynamic not statis. If you're working in your local machine, you can keep it as localhost.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | El Mehdi OUAFIQ |
