CurlException: Couldn't connect to server

I have rest api and web client and mongo db in VS 2017 entp with docker support in built.
Evrything works fine in docker if i run api and web client independently.
Issue is when i try to connect/communicate to api from web client i get “curl exception Couldn't connect to server” error.
Interestingly i can communicate from rest api to mongodb.below is the code and docker-compose file

version: '2'

services:
  api:
    image: api
    build:
      context: ./Api
      dockerfile: Dockerfile
    depends_on:
      - db
    ports:
      - "5000:80"
      
  db:
    container_name: mongodb
    image: mongo
    ports:
      - "32773:27017"

  apitestwebclient:
    image: apitestwebclient
    build:
      context: ./.ApiTestWebClient
      dockerfile: Dockerfile
    ports:
      - "5001:80"
    links:
      - .idserver

  idserver:
    image: idserver
    build:
      context: ./IDServer
      dockerfile: Dockerfile
    ports:
      - "5002:80"

Code

 using (var client = new HttpClient())
            {
                var data = await client.GetAsync("http://localhost:5000/api/incident/" + id);
                return await data.Content.ReadAsStringAsync();
            }

I have also added cors support in api

 app.UseCors(policy =>
            {
                policy.AllowAnyHeader();
                policy.AllowAnyMethod();
                policy.AllowAnyOrigin();
                policy.AllowCredentials();
            });

Any help is apperciated