且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Docker组合服务无法通过服务名称进行通信

更新时间:2023-12-02 19:16:28

由于您使用的是docker-compose.yml版本2,因此不需要链接.组成网络中的容器应能够按服务名称解析其他组成容器.

Since you are using docker-compose.yml version 2, links should not be necessary. Containers within a compose network should be able to resolve other compose containers by service name.

阅读有关问题的评论似乎可以解决网络和主机名解析问题,因此问题似乎出在您的Web UI中.我看不到您将任何类型的配置传递给UI应用程序,说明在何处可以找到api.也许您的用户界面中有一个指向api的硬编码网址,从而导致错误?

Reading the comments on your question it seems like the networking and host name resolution works, so it seems like the problem is in your web UI. I don't see you passing any type of configuration to the UI application saying where to find the api. Maybe there is a hard coded url to the api in your UI causing the error?

您的UI是客户端/javascript应用程序吗?您确定该应用程序实际上不是从您的浏览器拨打电话吗?您在本地计算机而非docker上运行的浏览器将无法解析badderrer-api主机名.

Is your UI a client side/javascript app? Are you sure the app isn't actually making the call from your browser? Your browser running on your local machine and not in docker will not be able resolve the badderrer-api hostname.