Troubleshooting / Unable to Access the Internet in Code
When the code cannot access the internet within the script, it is mostly due to DNS or firewall issues.
The specific manifestations are as follows when executing code similar to requests.get('http://bing.com')
:
Temporary failure in name resolution
Connection refused
Connection to bing.com timed out
- Other network errors
You can perform the following operations sequentially to troubleshoot the issue:
- Execute
ping 8.8.8.8
on the host machine to check if the host can access the public internet. - Execute
curl http://bing.com
on the host machine to check if the host's DNS is functioning properly. - Execute
docker exec -it {DataFlux Func container ID} sh -c 'exec ping 8.8.8.8'
to check if the container can access the public internet. - Execute
docker exec -it {DataFlux Func container ID} sh -c 'exec curl http://bing.com -i'
to check if the DNS within the container is functioning properly.
8.8.8.8
is a commonly used public DNS server address.
If the installed DataFlux Func image does not have the ping
command, you can use curl http://{IP address}
as an alternative.
Possible causes and solutions:
Possible Cause | Solution |
---|---|
Host machine cannot access the public internet, DNS is not functioning | Check and adjust the operating system network configuration. |
Container cannot access the public internet, DNS is not functioning | Check and adjust Docker-related configurations, and if necessary, check the operating system network configuration. |
Docker DNS Configuration Guide
Edit the /etc/docker/daemon.json
file, add the following content, save it, and restart the Docker service:
JSON | |
---|---|
1 2 3 4 5 6 |
|