[英]cURL same server from a inside docker container
I saw a lot of similar problem but not exactly like mine... I have a classic architecture,我看到了很多类似的问题,但并不完全像我的......我有一个经典的架构,
A server with docker, a stack with Traefik to dispatch request, and few stack of nginx/apache and php. Let's say一个带有 docker 的服务器,一个带有 Traefik 的堆栈来调度请求,以及一些 nginx/apache 和 php 的堆栈。假设
The problem is that I can't cURL another website from inside a docker container.问题是我无法从 docker 容器中访问另一个网站 cURL。
If I try to curl from server itself如果我尝试从服务器本身访问 curl
curl -v website2.com
curl -v https://website2.com
I get a valid response我得到一个有效的回应
If I try to curl from website1 container如果我尝试从 website1 容器访问 curl
curl -v website2.com
curl -v https://website2.com
I can see我可以看到
Trying XX.XX.XX.XX:443...
正在尝试 XX.XX.XX.XX:443...
With my external IP (so the DNS should be OK) but I don't get any response so it end with a timeout message.使用我的外部 IP(因此 DNS 应该没问题)但我没有收到任何响应,因此它以超时消息结束。
If I add 192.168.48.4 website2.com
into my /etc/hosts
and I try to cURL, I get a valid response but tell me if I'm wrong but in this case it access through local and not from outside of the server如果我将
192.168.48.4 website2.com
添加到我的/etc/hosts
中并尝试使用 cURL,我会得到一个有效的响应,但如果我错了,请告诉我,但在这种情况下,它是通过本地访问的,而不是从服务器外部访问的
By the way, I need to cURL from a "manager" website that get all domains from an API, so cURL should be dynamic and I can't really add all IP manually into a hosts file or whatever顺便说一句,我需要从“经理”网站获取 cURL,该网站从 API 获取所有域,因此 cURL 应该是动态的,我不能真正将所有 IP 手动添加到主机文件或其他文件中
I really want to access other containers from outside, like an external service我真的很想从外部访问其他容器,比如外部服务
Do you have any suggestion?你有什么建议吗? Thank you guys
感谢你们
Thanks for comment and specifically to this topic https://community.traefik.io/t/curl-from-container-a-to-b-blocked/1040/14感谢您的评论,特别是对此主题的评论https://community.traefik.io/t/curl-from-container-a-to-b-blocked/1040/14
In my case, the firewall (ufw) of my host was "blocking" my http/https requests, even if my domains were accessible在我的例子中,我主机的防火墙 (ufw) 正在“阻止”我的 http/https 请求,即使我的域可以访问
Thoses commands fix my problem这些命令解决了我的问题
sudo ufw allow http
sudo ufw allow https
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.