Connection refused on port :80


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,", 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 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 \"[``\](``": dial tcp : connect: connection refused","time":"2020-07-01T14:59:58Z"} .

Here is my docker-compose.yml:
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!

Welcome to the forum @0x113

When they are running in the container the localhost is the container itself not the host that docker runs on.

Compose should have put these all on the same network, inter container communication will work just fine using the container-name. So if I read your configuration correctly your service should use http://xmedia-user-svc/api/v1/.....

Thank you, it worked!