3

We have a remote postgres database(an amazon rds db) which we need to access from docker django application, how can we link the same ?

How my django-compose.yml should look in that case ?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

this is basically exactly what i was refering in mysq question and actually only needed if you have no external DNS resolver - the external connection is still needed, its nothing "link" like
we would need to mention port as well(in ports section) ?
the ports section only specifies which ports are exposed to outside the docker-world (e.g. mapped to your external IP address). In your case it's probably just port 80
@Neo the easy answer is to always use the standard postgres port and just make that assumption. If you need a different port, you should specify that with an environment variable passed to the container.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.