$ docker run -d
--name some-postgres
-e POSTGRES_USER=postgres
-e POSTGRES_PASSWORD=mysecretpassword
-p 5432:5432
postgres
I build postgresql container like above. Then when try to access Postgresql server. I always set the IP address like this in Python with Flask-SQLAlchemy:
app.config['SQLALCHEMY_DATABASE_URI'] = postgresql://postgres:[email protected]:5432/some_db_name'
instead of writing "host.docker.internal" can I set the IP address as static one?
2
Answers
You need to create a custom network:
then, run the container
You can also choose the IP addresses for the container with –ip and –ip6 flags when you start the container on a user-defined network. See Connect a container to a network
Example:
If you never created a docker network, also check out docker network create.