Home > Back-end >  Resource temporarily unavailable in Docker container when connecting to grpc endpoint
Resource temporarily unavailable in Docker container when connecting to grpc endpoint

Time:11-19

I am trying to connect to my grpc service within a docker container however when my code runs to connect it gives out a Resource Temporarily Unavailable error.

Docker-compose for dev container. I spin this up using: docker-compose -f .devcontainer/docker-compose.yml up

version: "3.8"
services:
    app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        # Update 'VARIANT' to pick a version of .NET: 3.1, 5.0, 6.0
        VARIANT: "6.0"
        # Optional version of Node.js
        NODE_VERSION: "lts/*"
    image: company/devcontainer:latest
    environment:
      - UNIT_TESTS=/workspace/test
      - ACCEPTANCE=/workspace/acceptance
      - DOCKER_HOSTNAME=host.docker.internal

    # Attaches Host Docker Daemon to devcontainer and directories
    volumes:
      - ..:/workspace:cached
      - /var/run/docker.sock:/var/run/docker.sock

Docker-compose for grpc service

version: "3.8"
services:
    my-app:
        image: ${MY_APP_IMAGE_NAME:-company/my-app}
        restart: on-failure
        ports:
          - '3000:3000'
        extra_hosts:
          - "host.docker.internal:host-gateway"

C# Code to connect to my-app which is a grpc service

using var channel = GrpcChannel.ForAddress(
                "http://my-app:3000",
                channelOptions: new GrpcChannelOptions() {
                    Credentials = Grpc.Core.ChannelCredentials.Insecure
                });

When I run the test locally with visual studio using localhost:3000 it works fine. I spin up everything using the docker-compose up command. Once I try to use my grpc channel I get resource temporarily unavailable but I do see the service spin up within docker.

CodePudding user response:

As I noted in the comments, the problem is running services on different networks. One possible solution would be to create a network manually

docker network create my-network

Then set the default external network in both docker-compose files

networks:
  default:
    external: true
    name: my-network

For more info: https://docs.docker.com/compose/compose-file/#networks-top-level-element

  • Related