I was trying to create two docker images: asp.net core and postgresq, but connection string doesnt recognize properly the port.
This is the docker-compose.yml
file:
version: '3.4'
networks:
-default:
driver: bridge
services:
netcoreapi:
image: netcoreapi:latest
depends_on:
- "postgres_image"
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:80"
networks:
- default
environment:
netcoreapiContext: "host=postgres_image;port=5432;database=gr10_db;username=gr10;password=12345678"
postgres_image:
image: postgres:latest
ports:
- "5432"
restart: always
volumes:
- db_volume:/var/lib/postgresql/data
environment:
POSTGRES_USER: "gr10"
POSTGRES_PASSWORD: "12345678"
POSTGRES_DB: "gr10_db"
networks:
- default
volumes:
db_volume:
and this is my appsettings.json
:
"AllowedHosts": "*",
"ConnectionStrings": {
"netcoreapiContext": "Server=127.0.0.1; port=5432;Database=gr10_db;Username=gr10;Password=12345678"
}
Nevertheless, when I test the database, it return me the following message:
System.ArgumentException: Keyword not supported: ‘port’.
at Microsoft.Data.Common.DbConnectionOptions.ParseInternal(Dictionary
2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)
if anyone could bring e some help, I’d be grateful
>Solution :
Try something like:
"netcoreapiContext":"Host=127.0.0.1;Port=5432;Database=gr10_db;Username=gr10;Password=12345678"
Some connection PostgreSQL connection strings examples can be found in Npgsql docs or here.