Issue with Dapr sidecar communication between services in Docker Compose

I’m encountering an issue with Dapr sidecar communication between two services (service1 and service2) in Docker Compose. Here’s my setup:

service1 communicates with service2 through Dapr’s sidecar using HTTP.
Both services and Dapr are configured in docker-compose.yml with the appropriate ports and dependencies.
When service1 tries to invoke service2 via Dapr using the endpoint http://localhost:8000/v1.0/invoke/service2/method/endpoint, it fails with the error:

{
    "errorCode": "ERR_DIRECT_INVOKE",
    "message": "failed to invoke, id: service2, err: Post "http://127.0.0.1:5002/endpoint": dial tcp 127.0.0.1:5002: connect: connection refused"
}

However, http://localhost:5002/endpoint does work.

Here are the relevant:
docker-compose.yml:


version: '3.9'

services:
  service1:
    build: ./service1
    ports:
      - "5001:5001"
    depends_on:
      - dapr
    environment:
      - APP_PORT=5001
    networks:
      - mynetwork

  service2:
    build: ./service2
    ports:
      - "5002:5002"
    depends_on:
      - dapr
    environment:
      - APP_PORT=5002
    networks:
      - mynetwork

  dapr:
    image: "daprio/daprd:latest"
    command: [
      "./daprd",
      "-app-id",
      "service2", 
      "-app-port",
      "5002", 
      "-dapr-http-port", 
      "8000", 
      "-components-path", 
      "/dapr/components", 
      "-config", 
      "/dapr/configuration.yaml"
      ]
    volumes:
      - ./dapr:/dapr
    ports:
      - "8000:8000"
    networks:
      - mynetwork

networks:
  mynetwork:
    driver: bridge

configuration.yaml:

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: daprConfig
spec:
  tracing:
    samplingRate: "1"

pubsub.yaml is empty

Service 1 — app.py:

from flask import Flask, request
import requests

app = Flask(__name__)

@app.route('/invoke', methods=['POST'])
def invoke():
    payload = request.json
    response = requests.post('http://localhost:8000/v1.0/invoke/service2/method/endpoint', json=payload)
    return response.json()

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5001)

Servic 2 — app.py:

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/endpoint', methods=['POST'])
def endpoint():
    data = request.json
    return jsonify({"message": "Hello from Service 2", "data": data})

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5002)

docker-compose logs dapr

poc-dapr-1  | Flag --components-path has been deprecated, use --resources-path
poc-dapr-1  | time="2024-07-17T08:55:21.043345396Z" level=info msg="Starting Dapr Runtime -- version 1.13.5 -- commit e490e58f62110ecdc430d2f39d57428729a487ea" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.043513409Z" level=info msg="Log level set to: info" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.045307341Z" level=warning msg="mTLS is disabled. Skipping certificate request and tls validation" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.security type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.076611723Z" level=warning msg="The default value for 'spec.metric.http.increasedCardinality' will change to 'false' in Dapr 1.14" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.126179456Z" level=info msg="standalone mode configured" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.126419523Z" level=info msg="app id: service2" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime 
type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.126560728Z" level=info msg="metrics server started on :9090/" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.126646141Z" level=info msg="Dapr trace sampler initialized: DaprTraceSampler(P=1.000000)" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.137772598Z" level=info msg="local service entry announced: service2 -> 172.26.0.2:48514" app_id=service2 component="nr (mdns/v1)" instance=3b25aa53d9cb scope=dapr.contrib type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.138366125Z" level=info msg="Initialized name resolution to mdns" app_id=service2 instance=3b25aa53d9cb 
scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.139687587Z" level=info msg="Loading components…" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.186632178Z" level=info msg="Waiting for all outstanding components to be processed…" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.186878278Z" level=info msg="All outstanding components processed" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.187139399Z" level=info msg="Loading endpoints…" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.234287131Z" level=info msg="Waiting for all outstanding http endpoints to be processed…" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.234587307Z" level=info msg="All outstanding http endpoints processed" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.235049017Z" level=info msg="gRPC server listening on TCP address: :50001" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.grpc.api type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.235245793Z" level=info msg="Enabled gRPC tracing middleware" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.grpc.api type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.235289715Z" level=info msg="Enabled gRPC metrics middleware" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.grpc.api type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.235585783Z" level=info msg="Registering workflow engine for gRPC endpoint: [::]:50001" app_id=service2 
instance=3b25aa53d9cb scope=dapr.runtime.grpc.api type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.235937359Z" level=info msg="API gRPC server is running on port 50001" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.236263142Z" level=info msg="Enabled max body size HTTP middleware with size 4 MB" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.http type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.236447767Z" level=info msg="Enabled tracing HTTP middleware" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.http type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.236492016Z" level=info msg="Enabled metrics HTTP middleware" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.http type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.23799336Z" level=info msg="HTTP server listening on TCP address: :8000" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.http type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.238381051Z" level=info msg="HTTP server is running on port 8000" app_id=service2 instance=3b25aa53d9cb 
scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.238537041Z" level=info msg="The request body size parameter is: 4" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.238792905Z" level=info msg="gRPC server listening on TCP address: :48514" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.grpc.internal type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.23887658Z" level=info msg="Enabled gRPC tracing middleware" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.grpc.internal type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.238904045Z" level=info msg="Enabled gRPC metrics middleware" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime.grpc.internal type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.239145982Z" level=info msg="Internal gRPC server is running on port 48514" app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5
poc-dapr-1  | time="2024-07-17T08:55:21.239486459Z" level=info msg="application protocol: http. waiting on port 5002.  This will block until the app is listening on that port." app_id=service2 instance=3b25aa53d9cb scope=dapr.runtime type=log ver=1.13.5

Any suggestions on how to troubleshoot or fix this issue would be greatly appreciated. Thank you!

New contributor

Max Strauss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật