docker-compose.yml文件中postgresql的连接字符串

问题描述 投票:3回答:1

我正在使用docker支持运行NetCore项目。我的docker-compose.override.yml:

version: '3.4'

services:
  traefik:
    ports:
      - '80:80'
      - '443:443'
      - '8080:8080'

  myapi:
    environment:
      - 'ASPNETCORE_ENVIRONMENT=Development'
      - 'ConnectionStrings:DbConnection=postgresql://postgres'
      - 'Services:Authorization=http://10.0.75.1'
      - 'Authorization:Url=http://10.0.75.1'

  postgres:
    environment:
      POSTGRES_USER: "user"
      POSTGRES_PASSWORD: "pass"
      POSTGRES_DB: testdb
    ports:
      - 5432:5432

  pgadmin4:
    environment:
      - [email protected]
      - PGADMIN_DEFAULT_PASSWORD=SuperSecret
    ports:
     - 19000:80

和docker-compose.yml:

version: '3.4'

services:
  traefik:
    image: traefik
    command: --web --docker --docker.domain=docker --logLevel=DEBUG
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /develop/traefik/acme:/etc/traefik/acme

  postgres:
    image: postgres
    labels: { "traefik.enable":"false" }

  myapi:
    image: myapi
    build:
      context: .
      dockerfile: MyApi/Dockerfile
    links:
      - postgres
    labels: { "traefik.backend":"myapi", "traefik.frontend.rule":"PathPrefixStrip:/" }

  pgadmin4:
    image: dpage/pgadmin4
    links:
      - postgres

我无法将myapi服务的连接字符串绑定到postgres docker容器。我也尝试过postgresql:// postgres:postgres @ db:5432,和postgresql://,只是postgres,没有运气。

我得到日志:

System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

显然我无法访问数据库服务器。

当我在本地运行应用程序时,我的原始连接字符串在表单中运行良好:

User ID = user; Password = pass; Server = localhost; Port = 5432; Database = testdb; Integrated Security = true; Pooling = true

有关如何在Docker中使用postgres映射我的服务的任何想法吗?谢谢!

postgresql docker docker-compose
1个回答
2
投票

我想你应该用这个:

User ID = user;Password=pass;Server=postgres;Port=5432;Database=testdb;Integrated Security=true;Pooling=true
© www.soinside.com 2019 - 2024. All rights reserved.