Using Postgres inside docker container

These are my personal notes. Am running postgres docker image on a local linux box.

If port 5432 is already in use, run this to see what process is using it:

sudo ss -lptn 'sport = :5432'

the above command will also display the pid using which you can kill the process. For example, if the pid is 1667, kill it by sudo kill 1667

Now sudo launch the shell script that runs the docker image.

Connecting to the postgres database within the container

First get the pid of the docker process: sudo docker ps

Now login to the root of the docker instance: sudo docker exec -it bdd95244ce47 bash
(Here bdd95244ce47 was the pid of the docker process from prev step, change it to whatever the pid is)

Then login to postgres root like so; psql -U postgres

then you can list databases like so: \l

connect to database: \c whatever_db_name

display all tables within connected database: \dt

Tek Shinobi
Author: Tek Shinobi

Hiya Ninjas, I am the ninja who invented the fire, wheel, science, technology and everything intelligent this humanity has ever experienced since its evolution from monkeys and germs. Actually, above is a partial list. I also was involved with the Big Bang that created this universe. What was it like before the Big Bang is so secret that if I tell you, I will have to turn you into a hobbit and force you to be my gardener. Okay. Sayonanra, Namaste Tek Shinobi

No Comments

You can leave the first : )

Leave a Reply

Your email address will not be published. Required fields are marked *