Connecting to Postgresql in a docker container from outside

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

    I am using django with postgres in Docker containers. in the docker-compose file, add the following:

    db:
        image: postgres:10-alpine
        environment:
            - POSTGRES_DB=app
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=supersecretpassword
        **ports:
            - "6543:5432"**
    

    which will add accessible port by your local machine. for myself, I connected DBeaver to it. this will prevent port clashes between your app request and local machine request. at first, I got a message saying that the port 5432 is in use (which is by django app) so I couldn't access by pgAdmin or DBeaver.

提交回复
热议问题