Connecting to Postgresql in a docker container from outside

后端 未结 14 2001
太阳男子
太阳男子 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 tried to connect from localhost (mac) to a postgres container. I changed the port in the docker-compose file from 5432 to 3306 and started the container. No idea why I did it :|

    Then I tried to connect to postgres via PSequel and adminer and the connection could not be established.

    After switching back to port 5432 all works fine.

      db:
        image: postgres
        ports:
          - 5432:5432
        restart: always
        volumes:
          - "db_sql:/var/lib/mysql"
        environment:
          POSTGRES_USER: root
          POSTGRES_PASSWORD: password
          POSTGRES_DB: postgres_db
    

    This was my experience I wanted to share. Perhaps someone can make use of it.

提交回复
热议问题