Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection string for postgresql in docker-compose.yml file

I am running NetCore project with docker support. My 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

And 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

I can't bind connection string from myapi service to postgres docker container. I have also tried with postgresql://postgres:postgres@db:5432, and postgresql://, and just postgres, no luck.

I am getting log:

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

So obviously i cannot reach the db server.

My original connection string, when I run app locally, works great, in form:

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

Any ideas how to map my service with postgres in docker here? Thx!

like image 399
zlaayaa Avatar asked Jul 20 '18 12:07

zlaayaa


1 Answers

I think you should use this:

User ID = user;Password=pass;Server=postgres;Port=5432;Database=testdb;Integrated Security=true;Pooling=true
like image 56
Soorena Avatar answered Sep 20 '22 04:09

Soorena