我有以下 docker-compose 内容:
version: '3.4'
services:
reporting.service:
image: xxx.azurecr.io/beta/reporting.service
environment:
- ASPNETCORE_ENVIRONMENT=Docker
ports:
- "5003:80"
messaging.bus:
image: rabbitmq:3-management
environment:
- RABBITMQ_DEFAULT_USER=user
- RABBITMQ_DEFAULT_PASS=user
- RABBITMQ_DEFAULT_VHOST=test
links:
- reporting.service
ports:
- "15672"
- "5672"
web.frontend:
image: xxx.azurecr.io/beta/web.frontend
ports:
- "3000:80"
当使用docker在我的机器上本地运行时,一切正常,我的reporting.service能够毫无问题地连接到messaging.bus(RabbitMQ)。
连接字符串如下所示:
"EventBus": {
"ConnectionString": "amqp://user:user@messaging.bus:5672/test"
},
当我将图像推送到 Azure 容器注册表并尝试在 Azure Web 应用程序中将其用于容器时,reporting.service 容器中会引发以下异常:
RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.AggregateException: One or more errors occurred. (Connection failed) ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No such device or address
仅供引用,我在连接到 RabbitMQ 时在 reporting.service 中实现了 Polly 重试策略,以便在代理不可用的情况下多次执行代码。确保 RabbitMQ 容器启动并运行(我也确认了查看日志)。
我做错了什么?为什么我无法从其他容器中看到 rabbitMq 实例?
谢谢您的帮助!
最佳答案
我在 上遇到过类似问题Azure 应用服务 ,我解决它的方法是使用 友情链接 关键词。正如我从您的 docker-compose 中看到的那样,您以错误的方式链接它。它在本地工作的原因是容器在同一个本地网络中。
您是否尝试链接 报告服务至消息传递.bus 反而?
还要检查这个答案here , docker 官方文档 here和 docker 在 Azure here 上撰写支持的命令.
我还发现了一篇有趣的文章here这说明了如何制作两个相互依赖的容器。
我希望这有帮助!
关于docker - 在 Azure Web App for Containers 中无法访问 RabbitMQ 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54274697/