DEV Community

ankit-brijwasi
ankit-brijwasi

Posted on

Connect To Postgres database running on a Docker container using psql

Recently while working, I was required to connect to a database that was running on a docker container using psql.

If you are also dealing with something like this, then, follow along

1. Start the docker container

$ docker run -d container_name
Enter fullscreen mode Exit fullscreen mode

2. Now run the following command

$ psql -h localhost -p 5432 -U username -d database_name
Password for user username:

psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1))
Type "help" for help.
database_name=> 
Enter fullscreen mode Exit fullscreen mode

And that's it
Thank you for reading!
Have a nice day!😇

Top comments (0)