英文:
Docker Get http://localhost:8091/api/order: dial tcp 127.0.0.1:8091: connect: connection refused
问题
我在Docker中有两个容器:
- Golang服务
- Odoo服务
Golang服务将会调用Odoo服务的API。
我尝试过在没有使用两个Docker容器的情况下,一切都正常工作。但是当我将我的Golang服务放入Docker容器中时,出现了这个错误。
我知道这篇帖子:https://stackoverflow.com/questions/54397463/getting-error-get-http-localhost9443-metrics-dial-tcp-127-0-0-19443-conne
这是我在Golang中定义Odoo URL的方式:
var OdoobaseURL = "http://localhost:8091/api/order"
但是我该如何在Golang中解决这个问题呢?谢谢。
英文:
i have 2 containers in Docker:
- golang service
- odoo service
the golang service will hit api in odoo service
i've tried it without 2 docker containers it works fine but when i make my golang service into docker container i got this error
im aware of this post https://stackoverflow.com/questions/54397463/getting-error-get-http-localhost9443-metrics-dial-tcp-127-0-0-19443-conne
this is how i define my odoo url in golang
var OdoobaseURL = "http://localhost:8091/api/order"
but how can i solve it in golang? thanks
答案1
得分: 0
当使用Docker Compose运行应用程序时,您需要通过服务名称来访问目标容器。当单独运行Go服务时,您需要暴露odoo
服务端口,然后可以使用localhost
进行连接。
英文:
When running your application with Docker Compose you'll have to address the target container via it's service name. When running the Go service separately you'll have expose the odoo
service port and then you can use localhost
to connect.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论