I'm developing a project in .Net 5 the database used is Postgres. I'm using a docker-compose file database, but when I run the dotnet ef database update
command I get the following error:
Build started...
Build succeeded.
Npgsql.NpgsqlException (0x80004005): Exception while connecting
---> System.Net.Sockets.SocketException (111): Connection refused
at Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
....
Exception while connecting
Docker-Compose:
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_USER: Guilherme
POSTGRES_PASSWORD: XXXX
POSTGRES_DB: BuiltCode
pgadmin:
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: root
ports:
- "5050:80"
Connection String:
"PostgreSql": "Username=Guilherme;Password=XXXX;Server=localhost;Port=5432;Database=BuiltCode;"
Could someone help me, please?
CodePudding user response:
Add under db
section:
ports:
- '5432:5432'