My app could read the database. pgAdmin couldn't. Both were pointing at "localhost:5432"
I was running a FastAPI app in Docker with a PostgreSQL container next to it. The app worked. It wrote rows, it read them back, everything behaved. The database itself, fastapi-db , was one I'd created inside the dockerised PostgreSQL — the container defined in my compose file. My app had created the products table in it and was happily writing rows. Then I opened pgAdmin to look at that data…
In a Dockerized FastAPI app, an application could interact with a PostgreSQL database while pgAdmin, a graphical interface, was unable to access the same database. Both the application and pgAdmin were pointing at localhost:5432, but they were connected to different databases. The app was working correctly within the Docker container, while pgAdmin was connected to a separate PostgreSQL instance running on the Windows host machine.
To resolve the issue, the host-side port mapping needed to be adjusted to avoid collision. The port number on the host machine should be different from the port inside the container. This allowed pgAdmin to connect to the correct database, and the FastAPI application continued functioning as expected without any changes to its configuration.
The distinction between container networks and host networks is crucial in understanding the scope of connectivity and avoiding confusion between services running in different environments.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.