Connecting to Postgresql in a docker container from outside

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

    I already had running postgres on host machine and didn't want to allow connections from network, so I did run temporary postgres instance in container and created database in just two lines:

    # Run PostgreSQL
    docker run --name postgres-container -e POSTGRES_PASSWORD=password -it -p 5433:5432 postgres
    
    # Create database
    docker exec -it postgres-container createdb -U postgres my-db
    

提交回复
热议问题