title: Dapr GRPC connection Refused while getting state using .net DaprClient
body: <p>I tried a few links (and trying out suggestions posted (<a href="https://github.com/dapr/dotnet-sdk/issues/609" rel="nofollow noreferrer">https://github.com/dapr/dotnet-sdk/issues/609</a>)  before posting this question , so apologies in advance if this has been repeated before. Would appreciate any pointers . Thanks in advance.</p>
  <ul>
  <li><p>I have a .net core application and I am able to save, store and retrieve the state in the self hosted dapr dev environment that comes with dapr_Redis , dapr_zipkin and dapr_placement containers. The app however is running locally and everything works great. I am able to retrieve all the keys from dapr_redis and use them in the application. The command I used to test all this is------------------&gt;</p>
  <p><em>dapr run --app-id DaprMyApp  --dapr-http-port 3500 --components-path ./components dotnet run</em>.</p>
  </li>
  <li><p>Now , I  have them in a docker-compose file and my app is also containerized (ps: without any Dapr the app runs perfectly fine in docker).  When this line executes -----&gt;</p>
  </li>
  <li><p>await daprClient.GetStateEntryAsync &lt;IList &lt;ServicePrincipal&gt;&gt;(storeName, &quot;LightApplications&quot;);</p>
  <p>The following error is displayed
  <em>Dapr.DaprException: State operation failed: the Dapr endpoint indicated a failure. See InnerException for details.</em>
  ---&gt; Grpc.Core.RpcException: Status(StatusCode=&quot;Internal&quot;, Detail=&quot;Error starting gRPC call. HttpRequestException: Connection refused SocketException: Connection refused&quot;, DebugException=&quot;System.Net.Http.HttpRequestException: Connection refused
  ---&gt; System.Net.Sockets.SocketException (111): Connection refused</p>
  </li>
  </ul>
  <p><strong>From the daprd container logs</strong>
  time=&quot;2022-03-30T22:23:13.1586783Z&quot; level=info msg=&quot;all outstanding components processed&quot; app_id=DaprMyApp  instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6.1</p>
  <p>time=&quot;2022-03-30T22:23:13.1588662Z&quot; level=info msg=&quot;enabled gRPC tracing middleware&quot; app_id=DaprMyApp   instance=6e094eaea3b2 scope=dapr.runtime.grpc.api type=log ver=1.6.1</p>
  <p>time=&quot;2022-03-30T22:23:13.1589773Z&quot; level=info msg=&quot;enabled gRPC metrics middleware&quot; app_id=DaprMyApp  instance=6e094eaea3b2 scope=dapr.runtime.grpc.api type=log ver=1.6.1</p>
  <p><strong>time=&quot;2022-03-30T22:23:13.1592719Z&quot; level=info msg=&quot;API gRPC server is running on port 50001&quot; app_id=DaprMyApp   instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6.1</strong></p>
  <p>time=&quot;2022-03-30T22:23:13.1598482Z&quot; level=info msg=&quot;enabled metrics http middleware&quot; app_id=DaprMyApp  instance=6e094eaea3b2 scope=dapr.runtime.http type=log ver=1.6.1</p>
  <p>time=&quot;2022-03-30T22:23:13.1599458Z&quot; level=info msg=&quot;enabled tracing http middleware&quot; app_id=DaprMyApp  instance=6e094eaea3b2 scope=dapr.runtime.http type=log ver=1.6.1</p>
  <p>time=&quot;2022-03-30T22:23:13.1601179Z&quot; level=info msg=&quot;http server is running on port 3500&quot; app_id=DaprMyApp  instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6.1</p>
  <p>time=&quot;2022-03-30T22:23:13.1601313Z&quot; level=info msg=&quot;The request body size parameter is: 4&quot; app_id=DaprMyApp   instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6.
  ......
  time=&quot;2022-03-30T22:23:13.1609711Z&quot; level=info msg=&quot;dapr initialized. Status: Running. Init Elapsed 175.1433ms&quot; app_id=DaprCirrus instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6.1</p>
  <ul>
  <li><p><strong>The docker-compose file looks like</strong></p>
  <p>version: &quot;3.8&quot;
  services:
  app:
  image: DaprMyApp:latest
  deploy:
  replicas: 1
  ports:
  - &quot;5001:5001&quot;
  # - &quot;50001:50001&quot;
  depends_on:
  - redis
  volumes:
  - type: bind
  source: c:\trust<br />
  target: /root/.dotnet/https
  environment:
  - DAPR_HOST=host.docker.internal
  - DAPR_GRPC_PORT=50001
  - ASPNETCORE_URLS=https://+:5001;http://+:5000</p>
  <pre><code>app-dapr:
    image: &quot;daprio/daprd:latest&quot;
    #command: [ &quot;./daprd&quot;, &quot;-app-id&quot;, &quot;DaprMyApp&quot;, &quot;-components-path&quot;, &quot;/components&quot; ]
    command: [&quot;./daprd&quot;,
     &quot;-app-id&quot;, &quot;app&quot;,
     &quot;-placement-host-address&quot;, &quot;placement:50006&quot;,
     &quot;-dapr-http-port&quot;, &quot;3500&quot;,
     &quot;-dapr-grpc-port&quot;, &quot;50001&quot;,
     &quot;-components-path&quot;, &quot;/components&quot;]
    ports:
      - &quot;3500:3500&quot;
      - &quot;50001:50001&quot;
    volumes:
        - &quot;./components/:/components&quot;
    depends_on:
      - redis
    network_mode: &quot;service:app&quot;   
  
  redis:
    image: &quot;redis:alpine&quot;
    ports:
      - &quot;6379:6379&quot;
  </code></pre>
  </li>
  </ul>
  <p><strong>StateStore Yaml from Components folder</strong> WHen tested in use case 1 redis:6379 was replaced by localhost:6379 when the app was running locally .</p>
  <pre><code>apiVersion: dapr.io/v1alpha1
  kind: Component
  metadata:
    name: statestore
  spec:
    type: state.redis
    version: v1
    metadata:
    - name: redisHost
      value: redis:6379
    - name: redisPassword
      value: &quot;&quot;
    - name: actorStateStore
      value: &quot;true&quot;
  </code></pre>
  <p><strong>DataPoint2</strong>
  When all the containers come up as described in the docker compose file. the following command also works fine (test as described in <a href="https://github.com/dapr/dapr/issues/2838" rel="nofollow noreferrer">https://github.com/dapr/dapr/issues/2838</a>)
  Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '[{ &quot;key&quot;: &quot;name&quot;, &quot;value&quot;: &quot;Bruce Wayne&quot;}]' -Uri 'http://localhost:3500/v1.0/state/statestore'</p>
  <p><strong>DataPoint3</strong>
  If i start the sidecar separately -&gt;</p>
  <ul>
  <li><p>dapr run --app-id DaprMyApp  --dapr-http-port 3500 --components-path ./components</p>
  </li>
  <li><p>Check the port displayed for GRPC from above logs
  Checking if Dapr sidecar is listening on GRPC port 54799
  Dapr sidecar is up and running.
  You're up and running! Dapr logs will appear here.</p>
  </li>
  <li><p>Then add this port to the DAPR_GRPC_PORT to the environment variable of the machine</p>
  </li>
  <li><p>Then run the application separately in another window using dotnet run. Works perfectly,</p>
  </li>
  </ul>
  <p>I was hoping to have the app talk to the DAPR sidecar and get the info from the Redis container all in docker. Thanks in advance for any pointers.</p>