How to debug .net core in container?

I am working on .Net core project. There are eight container running parallel. Below is the screen shot.

Shows all containers

Whenever I run make start, all the containers starts running and I am able to run my UI and API’s as well. If I wanted to make changes in UI or API then I will make change in code and restart container It will work. I want to debug the API’s from postman. Whenever I try to debug the api code in vs code but I am getting exceptions in code where I am trying to communicate with other services running in container. In my case I am getting error when establishing connection with Postgres DB. Below is my docker.compose.yml

version: '3.4'

services:
  replenishment-ui:
    build:
      context: ../ipm-ui
      args:
        http_proxy: "${http_proxy}"
        https_proxy: "${https_proxy}"
      network: host # Need access to localhost for cntlm proxy
    image: replenishment-ui
    container_name: replenishment-ui
    links:
      - replenishment-service
    ports:
      - 8080:8080
    environment:
      API_HOST: 'replenishment-service'
      API_PORT: '5000'
      STAGE: 'local'
    volumes:
      - ../ipm-ui/src/:/work/src
    tty: true
    working_dir: /work
    command: "npm run start"

  replenishment-service:
    build:
      context: ./
      dockerfile: Dockerfile
      args:
        http_proxy: "${http_proxy}"
        https_proxy: "${https_proxy}"
      network: host # Need access to localhost for cntlm proxy
    environment:
      AWS_ACCESS_KEY_ID: 'abc'
      AWS_SECRET_ACCESS_KEY: 'abc'
      IPM_POSTGRES_USERNAME: 'kmart'
      IPM_POSTGRES_PASSWORD: 'kmart'
      IPM_POSTGRES_DATABASE: 'kmart'
      IPM_POSTGRES_ADDRESS: 'replenishment-postgres'
      IPM_POSTGRES_PORT: '5432'
      IPM_DB2_PASSWORD: 'paoi87y87y'
      IPM_DB2_USERNAME: 'db2inst1'
      IPM_KAFKA_SASL_USERNAME: 'kmart'
      IPM_KAFKA_SASL_PASSWORD: 'kmart'
      IPM_DSS_LOCAL_SQS_URL: 'http://replenishment-goaws:4100'
      IPM_DSS_SQS_URL: 'http://replenishment-goaws:4100/queue/local-queue1'
      ASPNETCORE_ENVIRONMENT: 'local'
      EXECUTE_INITIAL: 'true'
      http_proxy: 'http://httpgw.core.kmtltd.net.au:8080'
      https_proxy: 'http://httpgw.core.kmtltd.net.au:8080'
    image: replenishment-service
    container_name: replenishment-service
    ports:
      - 5000:5000
    links:
      - replenishment-postgres
      - db2
      - goaws
    depends_on:
      - replenishment-postgres

  goaws:
    image: pafortin/goaws
    container_name: replenishment-goaws
    ports:
      - 4100:4100

  replenishment-postgres:
    build:
      context: ./replenishment_data
    image: replenishment-postgres
    container_name: replenishment-postgres
    command: ["postgres", "-c", "log_statement=all"]
    volumes:
      - pg-data-cache:/var/lib/postgresql/data/
    ports:
      - 5432:5432

  db2:
    build:
      context: .
      dockerfile: Dockerfile-db2local
      args:
        http_proxy: "${http_proxy}"
        https_proxy: "${https_proxy}"
        LICENSE: 'accept'
    image: db2-local
    container_name: db2
    ports:
      - 50001:50001
    environment:
      LICENSE: 'accept'
      DB2INST1_PASSWORD: 'paoi87y87y'
    volumes:
      - ./scripts/db2:/scripts
      - db2-data-cache:/home/db2inst1/
    command: ["db2start"]

  zookeeper:
    image: confluentinc/cp-zookeeper:5.0.0
    hostname: zookeeper
    container_name: zookeeper
    logging:
      driver: none
    ports:
      - "2181:2181"
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000

  broker:
    image: confluentinc/cp-enterprise-kafka:5.0.0
    hostname: broker
    container_name: broker
    logging:
      driver: none
    depends_on:
      - zookeeper
    ports:
      - "9092:9092"
      - "29092:29092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092,PLAINTEXT_HOST://localhost:29092
      KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
      CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:9092
      CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper:2181
      CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
      CONFLUENT_METRICS_ENABLE: 'true'
      CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'

  schema-registry:
    image: confluentinc/cp-schema-registry:5.0.0
    hostname: schema-registry
    container_name: schema-registry
    logging:
      driver: none
    depends_on:
      - zookeeper
      - broker
    ports:
      - "8081:8081"
    environment:
      SCHEMA_REGISTRY_HOST_NAME: schema-registry
      SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: 'zookeeper:2181'

volumes:
  db2-data-cache:
  pg-data-cache:

Below stack trace.

Unhandled Exception: System.ArgumentException: Host can't be null
   at Npgsql.NpgsqlConnector.<Open>d__143.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnection.<Open>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.Internal.NpgsqlDatabaseCreator.Exists()
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
   at IPM.ReplenishmentService.DataContext.ReplenishmentParameterContext..ctor(DbContextOptions`1 options, Boolean migrate) in C:UsersngodboleDocumentsGitHubGitTestipm-serviceReplenishmentServiceDataContextReplenishmentParameterContext.cs:line 15
   at IPM.ReplenishmentService.Startup.ConfigureServices(IServiceCollection services) in C:UsersngodboleDocumentsGitHubGitTestipm-serviceReplenishmentServiceStartup.cs:line 99
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at IPM.ReplenishmentService.Program.BuildWebHost_NotRunByMigrations(String[] args) in C:UsersngodboleDocumentsGitHubGitTestipm-serviceReplenishmentServiceProgram.cs:line 31
   at IPM.ReplenishmentService.Program.Main(String[] args) in C:UsersngodboleDocumentsGitHubGitTestipm-serviceReplenishmentServiceProgram.cs:line 14

May I know what are the approaches to debug the APIs locally? If someone help me with available approaches to debug the It will be really helpful. Any help would be appreciated. Thank you

Source: StackOverflow