如何在容器中调试.net核心?

时间:2019-02-26 06:38:06

标签: api docker .net-core docker-compose containers

我正在从事.Net核心项目。有八个并行运行的容器。下面是屏幕截图。

显示所有容器

enter image description here

每当我运行make start时,所有容器都会开始运行,并且我也可以运行UI和API。如果我想在UI或API中进行更改,那么我将在代码中进行更改并重新启动容器。我想调试邮递员的API。每当我尝试调试vs代码中的api代码,但在代码中尝试与容器中运行的其他服务进行通信时,就会出现异常。就我而言,与Postgres DB建立连接时出现错误。下面是我的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:

在堆栈跟踪下方。

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:\Users\ngodbole\Documents\GitHub\GitTest\ipm-service\ReplenishmentService\DataContext\ReplenishmentParameterContext.cs:line 15
   at IPM.ReplenishmentService.Startup.ConfigureServices(IServiceCollection services) in C:\Users\ngodbole\Documents\GitHub\GitTest\ipm-service\ReplenishmentService\Startup.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:\Users\ngodbole\Documents\GitHub\GitTest\ipm-service\ReplenishmentService\Program.cs:line 31
   at IPM.ReplenishmentService.Program.Main(String[] args) in C:\Users\ngodbole\Documents\GitHub\GitTest\ipm-service\ReplenishmentService\Program.cs:line 14

我可以知道在本地调试API的方法是什么?如果有人通过可用的调试方法帮助我,那将非常有帮助。任何帮助,将不胜感激。谢谢

0 个答案:

没有答案