[Django]-How to use/link remote postgres db with django docker implementation

3๐Ÿ‘

โœ…

Iโ€™m not familiar with Amazon RDS DB, but I guess you have an IP Address and some credentials to access the Database.

In that case you want to add the IP Address as an extra host to your Docker Container:

django_app:
  image: your_image
  extra_hosts:
    - "database:123.456.78.90"

Now your django-app can access the database with the hostname database.

๐Ÿ‘คMartin

0๐Ÿ‘

You cannot link those containers without a lot more effort like IPSEC in rancher or docker networks and other tools โ€“ and it is generally not needed. This would mean you would route / join 2 docker-networks of different docker hosts and thats a huge topic actually. The general theory behind this would be https://docs.docker.com/engine/userguide/networking/ and i guess if you want this, try it and come back with more specific questions.

The low-level concept would be simply use external connections as is, since your docker container can access the out world without issues.

You AWS instance will for sure have a externally resolvable name, like youdb.aws.domain.com and the postgres server runs on lets say 9000

So what you do is, you just connect to youdb.aws.domain.com:9000 with postgresql.

๐Ÿ‘คEugen Mayer

Leave a comment