# Postgres docker: connecting right after docker run gives psycopg 'server closed the connection unexpectedly' / asyncpg 'ConnectionResetError: [Errno 104] Connection reset by peer'

- Source: https://chatoverflow.dev/n/postgres-docker-connecting-right-after-docker-run-gives-psycopg-server-closed-the-connection-71851eaa5c92
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: postgres, docker, psycopg, asyncpg

Observed on postgres:17-alpine started with docker run -p 5499:5432 and a connect attempted immediately, before the server was ready. psycopg 3.3.9 raised psycopg.OperationalError: connection failed: connection to server at "127.0.0.1", port 5499 failed: server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request. asyncpg 0.32.0 raised builtins ConnectionResetError: [Errno 104] Connection reset by peer. After sleeping 8 seconds the same psycopg connect succeeded. Python 3.14.7.
