-2

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 Getting error "Get http://localhost:9443/metrics: dial tcp 127.0.0.1:9443: connect: connection refused"

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

  • It depends how you run your containers (Go has nothing to do with that). How do you run them? With Docker compose you'll have to use the service name as the host, e.g. https://odoo:9443 – derkoe Jun 13 '21 at 12:04
  • i run golang service with dockerfile, and odoo with docker compose, in golang service it runs on port 8081 and odoo on port 8091 – Fahmi Roihan Jun 13 '21 at 12:08
  • i follow your suggestion but got this error 2021/06/13 12:09:52 Get odoo14:8091/api/order: unsupported protocol scheme "odoo14" my odoo service name is odoo14 – Fahmi Roihan Jun 13 '21 at 12:10
  • Try http://odoo14:8091/api/order (with "http://") – derkoe Jun 13 '21 at 12:19
  • thanks for the answer but now i got this error 2021/06/13 12:21:16 Get http://odoo14:8091/api/order: dial tcp: lookup odoo14 on 192.168.65.1:53: read udp 172.17.0.2:46205->192.168.65.1:53: i/o timeout, – Fahmi Roihan Jun 13 '21 at 12:22
  • You'll have to run all your service in the same docker-compose.yml file. Otherwise the network is not connected. What do you mean by running with Docker file? (You cannot run via Dockerfile.) – derkoe Jun 13 '21 at 12:29
  • sorry im just new with docker, so here i build image of golang service by dockerfile, and image successfully created with name odoo-sale, and i run the image using docker run -ti -p 8086:8080 odoo-sale, so you mean i need to create golang container by docker-compose with image that created by dockerfile right? – Fahmi Roihan Jun 13 '21 at 12:35

1 Answers1

0

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.

derkoe
  • 5,649
  • 2
  • 23
  • 31
  • i've upload my golang service into 1 docker-compose with my odoo service, so on url what should i use http://odoo14:8091/api/order, odoo14:8091/api/order, or odoo14/api/order – Fahmi Roihan Jun 13 '21 at 13:34
  • solved i use http://host.docker.internal:8091/api/order – Fahmi Roihan Jun 13 '21 at 14:45
  • That depends on what protocol odoo listens to and on which port. Looking at the odoo Docker image docs it should be http://odoo14:8069 – derkoe Jun 13 '21 at 14:49