Connecting to Postgresql in a docker container from outside

后端 未结 14 1937
太阳男子
太阳男子 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 14:57

    I managed to get it run on linux

    1. run the docker postgres - make sure the port is published, I use alpine because it's lightweight.

      sudo docker run --rm -P -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD="1234" --name pg postgres:alpine

    2. using another terminal, access the database from the host using the postgres uri

      psql postgresql://postgres:1234@localhost:5432/postgres

    for mac users, replace psql with pgcli

提交回复
热议问题