1

I was trying to setup my project on docker after going through few tutorials and guides. I am setting Elixir/Phoenix app which has Redis and Postgresql as it's dependencies. I have managed to Dockerize it using docker compose which uses images for pg and Redis.

I was trying to figure out a way to connect my Phoenix app to my local Postgresql and Redis instead of connecting it to their images as the db and Redis needs to be on the server and not in the docker container.

Is there any example someone could assist me with ?

Thanks in advance.

trojanh
  • 97
  • 9
  • what do you mean by `on the server`? The idea behind `docker-compose` is to run all your images in the same server. If you want to have an external database that is already running, that one does not belong to this compose file. In that case you should just use a general url to connect to it. – Mario F Sep 09 '17 at 19:37
  • I mean to say I do not want my Postgres and Redis to run on Docker. I want to know anyway to connect my Dockerized Phoenix app to Postgres and Redis outside of docker environment. To the ones that run on Linux servers normally. – trojanh Sep 09 '17 at 20:15

1 Answers1

0

By default, containers have 172.17.0.0/16 network and docker host has the address 172.17.0.1.

So you can just point your PostgreSQL and Redis URLs to that address, that is 172.17.0.1:5432 and 172.17.0.1:6379 respectively.

You will need to grant access to connections from this network Redis and PostgreSQL.

Gonzalo Matheu
  • 8,984
  • 5
  • 35
  • 58
  • 1
    Thanks. Really appreciate your help. Is there any documentation or quick reference for what you said? I would like to learn in detail about these things. – trojanh Sep 09 '17 at 20:12
  • 1
    Found this while browsing through Docker questions on Stackoverflow. https://stackoverflow.com/a/24326540/3861525 it answered all my questions about your answer. Anyway your answer was really helpful. Thanks – trojanh Sep 09 '17 at 20:42