[SOLVED] Connecting to Postgresql in a docker container from outside

I have tried to connect to Postgresql in a dcker container via HeidiSQL but it was failed on local machine.

But before lets practice with docker a little bit

In this section we will try to connect to Postgres inside docker container or you can jump down to SOLVED section in this article

docker container ls

With docker 1.3, there is a new command docker exec. This allows you to enter a running container:

docker exec -it [container-id] bash
docker exec -it 198805133df6 bash

If you want to exit the container

press ctrl+d
or type exit
root@198805133df6:/# exit
#docker exec -it [container-id] bash
docker exec -it 198805133df6 bash

#psql -h public-ip-server -p 5432 -U postgres
#psql -h localhost -p 5432 -U postgres
#on my local machine postgresql has name microservice33, so i should enter command like this
psql -h localhost -p 5432 -U microservice33

and 
\l
How to exit from postgres and docker container
microservice33=# \q
root@198805133df6:/# exit

SOLVED. How to connect to Postgresql using docker-compose

The only one thing helps me to connect successfully

Enter to docker-compose dir

And open docker-compose.yml file. Then you should enter POSTGRES_PASSWORD (don`t let it to be empy), and specify the port “5432:5432”

And try connecting to Postgresql in a docker container from outside

DONE