Connecting to Postgresql in a docker container from outside

后端 未结 14 2004
太阳男子
太阳男子 2020-11-29 14:42

I have Postgresql on a server in a docker container. How can I connect to it from the outside, that is, from my local computer? What setting should I apply to allow that?

14条回答
  •  伪装坚强ぢ
    2020-11-29 15:09

    To connect from the localhost you need to add '--net host':

    docker run --name some-postgres --net host -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres
    

    You can access the server directly without using exec from your localhost, by using:

    psql -h localhost -p 5432 -U postgres
    

提交回复
热议问题