docker run -it \ -e POSTGRES_USER="root" \ -e POSTGRES_PASSWORD="root" \ -e POSTGRES_DB="ny_taxi" \ -v $(pwd)/ny_taxi_postgres_data:/var/lib/postgresql/data \ -p 5432:5432 \ postgres:13
Here is the command that I use to create database.
When container has been created, another folder with similar name appears on my directory. Also, there is no file in my “ny_taxi_postgres_data” directory.
“ny_taxi_postgres_data;C” is the duplicate directory.
Then I try to access to the database by using pgcli with this command, it gives me this result.
$ pgcli -h localhost -p 5432 -u root -d ny_taxi Password for root: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "root"
My current container and network
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a510958c25ba postgres:13 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5432->5432/tcp condescending_feistel
$ docker network ls NETWORK ID NAME DRIVER SCOPE 066e01d5e304 bridge bridge local f896e9e41670 host host local 3fd1189d34cc none null local
Also, when there are no error on my logs when I try to access to database via pgcli.
As if my command can’t reach to database.
The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.utf8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /var/lib/postgresql/data ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Etc/UTC creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok initdb: warning: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: pg_ctl -D /var/lib/postgresql/data -l logfile start waiting for server to start....2022-08-13 09:33:05.185 UTC  LOG: starting PostgreSQL 13.8 (Debian 13.8-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit 2022-08-13 09:33:05.193 UTC  LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2022-08-13 09:33:05.224 UTC  LOG: database system was shut down at 2022-08-13 09:33:02 UTC 2022-08-13 09:33:05.236 UTC  LOG: database system is ready to accept connections done server started CREATE DATABASE /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/* waiting for server to shut down...2022-08-13 09:33:06.147 UTC  LOG: received fast shutdown request .2022-08-13 09:33:06.156 UTC  LOG: aborting any active transactions 2022-08-13 09:33:06.157 UTC  LOG: background worker "logical replication launcher" (PID 55) exited with exit code 1 2022-08-13 09:33:06.157 UTC  LOG: shutting down 2022-08-13 09:33:06.215 UTC  LOG: database system is shut down done server stopped PostgreSQL init process complete; ready for start up. 2022-08-13 09:33:06.281 UTC  LOG: starting PostgreSQL 13.8 (Debian 13.8-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit 2022-08-13 09:33:06.281 UTC  LOG: listening on IPv4 address "0.0.0.0", port 5432 2022-08-13 09:33:06.281 UTC  LOG: listening on IPv6 address "::", port 5432 2022-08-13 09:33:06.300 UTC  LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2022-08-13 09:33:06.320 UTC  LOG: database system was shut down at 2022-08-13 09:33:06 UTC 2022-08-13 09:33:06.332 UTC  LOG: database system is ready to accept connections