简体   繁体   English

cURL 来自内部 docker 容器的相同服务器

[英]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 的堆栈。假设

  • website1.com网站1.com
  • website2.com网站2.com

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.

相关问题 无法找到套接字传输“用户名”(docker容器内的cURL或作曲家) - unable to find the socket transport “username” (cURL or composer inside docker container) 不能 Curl docker 容器从容器外部运行 apache - Can't Curl docker container running apache from outside the container Docker:尝试在同一容器中联系应用程序时出现卷曲错误 - Docker: Curl errors when attempting to contact app in same container 来自容器内部的 Docker 复制作曲家供应商 - Docker copy composer vendor from inside container 使用 php 将文件从 docker 容器移动到同一服务器上的外部文件夹 - Move files from a docker container to an outside folder on the same server using php cUrl无法从同一服务器获取文件 - cUrl not able to get the file from same server 无法连接到在Docker容器中运行的套接字服务器 - Unable to connect to socket server running inside docker container 可以从 docker 容器外部连接到数据库,但不能从内部连接到数据库(在 laravel 中) - Can connect to database from outside a docker container but not from inside (in laravel) 从另一个Docker容器(同一主机,Apache)调用Docker容器中的API - Calling an API in a Docker container from a different Docker container (same host, Apache) Docker容器上的应用程序之间的卷曲连接被拒绝 - Curl connection refused between applications on Docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM