Title: How to connect docker container to bitcoin node? Post by: Exchangman on October 14, 2022, 08:43:23 AM I have a python script inside docker container and a bitcoin node outside of docker in my local machine , this is my bitcoin.conf information
Code: rpcuser=testuser and this is my docker compose conf file Code: app: then in my python script i'm trying to connect to the bitcoin node using this: Code: connection_url="http://%s:%s@localhost:8332/wallet/testwallet" when I make call to this script I get this error in return [Errno 111] Connection refused Ps: when I run the same script outside of docker container it works fine Any solutions?? ++ is it safe to run the node and connect to it using a script like this? locally? Title: Re: How to connect docker container to bitcoin node? Post by: vv181 on October 14, 2022, 11:21:58 AM You should use the internal IP on the Python container, not localhost.
Code: connection_url="http://%s:%s@host.docker.internal:8332/wallet/testwallet" If it still not works, try refer to https://www.howtogeek.com/devops/how-to-connect-to-localhost-within-a-docker-container/ Title: Re: How to connect docker container to bitcoin node? Post by: Exchangman on October 14, 2022, 11:33:21 AM You should use the internal IP on the Python container, not localhost. Code: connection_url="http://%s:%s@host.docker.internal:8332/wallet/testwallet" If it still not works, try refer to https://www.howtogeek.com/devops/how-to-connect-to-localhost-within-a-docker-container/ internal ip like 127.0.01? but that will connect to docker localhost network not the server localhost? Title: Re: How to connect docker container to bitcoin node? Post by: Exchangman on October 14, 2022, 11:41:58 AM when I make call to this script I get this error in return [Errno 111] Connection refused Ps: when I run the same script outside of docker container it works fine Any solutions?? I only use docker to run certain application, but AFAIK you got this error because you didn't perform port forwarding. On terminal, i'd use parameter -p HOST_PORT:CONTAINER_PORT (should be -p 8332:8332 in your case) to perform port forwarding. But i don't know the equivalent for Dockerfile. ++ is it safe to run the node and connect to it using a script like this? locally? Since you're the one who create the script, it should be safe. But if you have very serious security concern or writing script for business/enterprise usage, i'd recommend you to check whether library you use is malicious or not. So running on local and connecting to rpc on local is safe, just i have to check the python library that's all? How do i know that this library "https://github.com/jgarzik/python-bitcoinrpc" is safe? Title: Re: How to connect docker container to bitcoin node? Post by: vv181 on October 14, 2022, 12:41:08 PM You should use the internal IP on the Python container, not localhost. Code: connection_url="http://%s:%s@host.docker.internal:8332/wallet/testwallet" If it still not works, try refer to https://www.howtogeek.com/devops/how-to-connect-to-localhost-within-a-docker-container/ internal ip like 127.0.01? but that will connect to docker localhost network not the server localhost? I meant the internal IP of Docker. Since you already set host.docker.internal:host-gateway, you can try to use host.docker.internal as the IP, to access the IP outside Docker container. Try to use the modified code as I quoted above. Title: Re: How to connect docker container to bitcoin node? Post by: seoincorporation on October 27, 2022, 04:53:01 PM Another thing could be your server configuration because you need to one the port in the farewal to give access to the RPC calls.
Reference: https://stackoverflow.com/questions/11585377/python-socket-error-errno-111-connection-refused The way i did to personally fix this kind of issues in my local servers was with the command: Code: firewall-cmd --zone=public --add-port=8332/tpc --permanent And to verify your open ports you can use nmap: Code: nmap localhost Title: Re: How to connect docker container to bitcoin node? Post by: NotATether on October 27, 2022, 05:12:40 PM host.docker.internal is a domain name not an IP address. You need the IP address of the Docker container because bitcoin-cli doesn't do address resolution when connecting to the RPC server. You can find it using such tools as "ip addr" that show all the network interfaces - it will be called "docker0" or something like that.
|