Hi!
I recently started project based on microservices architecture and I have problem with calling from service A service B. I set up docker-compose and traefik, but I have problem with calling it when I use docker. Here is code, where I send request from service A (auth svc
) to service B(user svc
)
req, err := http.NewRequest(http.MethodPost, http://127.0.0.1/api/v1/user/validate", bytes.NewBuffer(jsonCreds))
if err != nil {
log.Errorf("Couldn't prepare request: %v", err)
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Host = "usersvc"
res, err := s.httpClient.Do(req)
if err != nil {
log.Errorf("Couldn't to execute request: %v", err)
return nil, err
}
When I run service A and service B separately and call http://127.0.0.1/api/v1/user/validate
with Host=usersvc
everything works ok, but when I want to execute the same code when I use docker-compose up
I get this error: {"level":"error","msg":"Couldn't to execute request: Post \"[``http://127.0.0.1/api/v1/user/validate\](http://127.0.0.1/api/v1/user/validate)``": dial tcp
127.0.0.1:80
: connect: connection refused","time":"2020-07-01T14:59:58Z"}
.
Here is my docker-compose.yml
: https://pastebin.com/Jkuxj8n6.
I'm trying call from the xmedia-auth-svc
to the xmedia-user-svc
I guess there is problem with networking, but I don't really know how to fix it. How can I call that service using traefik in docker?
Thanks in advance for the help!