Docker Community Forums

Share and learn in the Docker community.

Postgres .NetCore SocketException: Connection refused


(11111one11111) #1

Hi all so ive been bashing my head against this for a week and tried different things from google searches and still no joy. Im trying to link my .net core api docker image to the database but keep getting the socket exception

version: '2'

services:
postgresserver:
image: postgres
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: supersecret
POSTGTES_HOST: localhost
networks:
- mynetwork
volumes:
- pgdata:/var/lib/postgresql/data

viral.api:
image: viral.api
build:
context: ./Viral.Api
dockerfile: Dockerfile

links:
   - postgresserver:postgresserver
depends_on:
   - postgresserver
networks:
   - mynetwork

volumes:
pgdata:

networks:
mynetwork:
driver: bridge


the dkr file from the proj

FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT [“dotnet”, “Viral.Api.dll”]

the connection string

“Host=postgresserver;Port=5432;Username=postgres;Password=supersecret;Database=ViralDB”

Can anyone spot what im doing wrong?