Accessing Postgres using Docker CLIΒΆ
Let us understand how to connect to Postgres Database running as part of docker container using Docker CLI.
We can use
docker container execordocker execto connect to the container.You can attach to the container by running
bashusingdocker exec.Also you can run single commands with out attaching the container - example:
docker exec -it itv_pg hostname -f
You have to use terminal to run these commands
Attach to sms_db container -
docker exec -it itv_pg bashRun command to get hostname -
hostname -fRun command to connect to Postgres Database -
psql -U postgresYou can also directly connect to Postgres Database using
docker exec -it itv_pg psql -U postgres
Use
\qto come out of the Postgres CLI.