我用的是拉瑞多克。
我创建了多个项目。一个项目就是一个微服务。
我需要使用guzzle http从一个微服务到另一个微服务获取数据。
在laradock/nginx/sites我配置了所有的虚拟主机。
每个项目(微服务)单独工作都很好。
但是当我尝试从一个容器中获取数据时:
$url = "test.localhost/users";
$client = new \GuzzleHttp\Client();
$request = $client->get($url);
$response = $request->getBody();
return json_decode($response->getContents(), true);
我得到一个错误:
GuzzleHttp \ Exception \ ConnectException cURL错误7:无法连接到测试。localhost端口80:连接超时(请参见https://curl.haxx.se/libcurl/c/libcurl-errors.html)
我认为这是Docker的问题。
我试过:
networks:
frontend:
aliases:
- test.localhost
- test2.localhost
backend:
aliases:
- test.localhost
- test2.localhost
但没有用。
1条答案
按热度按时间db2dz4w81#
如果您使用
laradock
,请在主机上查看您的站点,然后将其列在laradock/docker-compose.yml
上,不是在nginx:
部分,而是在workspace:
中。之后,请重新启动docker
,输入docker-compose down
,然后再次输入up
。这是一个常见的问题,当你试图创建一个authentication
,我希望这将有助于。