I can't access the instance of Postgres running on a docker container from the PS. I seem to access a different instance... so how can I connect to the correct one?
Here I run the image:
docker run --name postgres-0 -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres:latest
260e6be6f6a9a1aa3050d6564ca59bffdcc691145902fa0e85a6eace620550d8
Here I check the container status:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
260e6be6f6a9 postgres:latest "docker-entrypoint.s…" 18 seconds ago Up 17 seconds 0.0.0.0:5432->5432/tcp postgres-0
Here I bash into the container:
docker exec -it postgres-0 bash
Here I start psql on the container:
root@260e6be6f6a9:/# psql -U postgres
Here I create a new database in the postgres instance of the container:
postgres=# CREATE DATABASE test;
CREATE DATABASE
Here I check the database I just created is actually there:
postgres=# \l
It is actually there.
Meanwhile on another PS window...
psql -U localhost -p 5432 -U postgres
When I check for the database present:
postgres=# \l
I get:
All of this on:
Windows 10 --> psql (PostgreSQL) 14.4,
Docker version 20.10.16, build aa7e414, --> psql (PostgreSQL) 14.3 (Debian 14.3-1.pgdg110+1)