Docker Get http://localhost:8091/api/order: dial tcp 127.0.0.1:8091: connect: connection refused

huangapple go评论117阅读模式
英文:

Docker Get http://localhost:8091/api/order: dial tcp 127.0.0.1:8091: connect: connection refused

问题

我在Docker中有两个容器:

  1. Golang服务
  2. 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:

  1. golang service
  2. 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.

huangapple
  • 本文由 发表于 2021年6月13日 19:56:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/67957969.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定