abhishek kavali
abhishek kavali

Reputation: 13

How do I connect the Postgres database running on the local machine to the docker container

I have a Flask application running on the container and Postgres database on the local machine and Now, I want to connect the Postgres DB (listening on 5432) to the docker container.

Can any one suggest the best way to do it ? (I am new to docker containers)

Thanks in advance.

Upvotes: 1

Views: 93

Answers (2)

so-random-dude
so-random-dude

Reputation: 16465

You can use the IP address of your local machine to connect to the postgres from your Docker container. localhost will not be resolvable in certain machines.

You may have some interest in this post. From inside of a Docker container, how do I connect to the localhost of the machine?

Upvotes: 0

Mitch
Mitch

Reputation: 1394

You'll likely want to Dockerize your Postgres database in its own container and use a persistent volume to store your data locally.

Tutorial on how to Dockerize your Postgres database: https://docs.docker.com/engine/examples/postgresql_service/

Documentation on Docker volumes: https://docs.docker.com/engine/tutorials/dockervolumes/

Postgres image on Docker Hub: https://hub.docker.com/_/postgres/

Upvotes: 1

Related Questions