Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django can't translate "postgres" name for postrgres database #5

Open
rllola opened this issue May 16, 2017 · 3 comments
Open

Django can't translate "postgres" name for postrgres database #5

rllola opened this issue May 16, 2017 · 3 comments

Comments

@rllola
Copy link

rllola commented May 16, 2017

I usually use the name of my docker-compose service inside my django application to connect to the database (postgres) but when I use the reverse proxy on the Django service it says it can't translate 'postgres' to a hostname :

could not translate host name "postgres" to address: Name or service not known

Usually docker-compose is able to do it.
Do you have any idea why it doesn't work when using the reverse-proxy and how I could fix it ?

@nknapp
Copy link
Contributor

nknapp commented May 30, 2017

I don't know if you still need the answer to your problem. I feel a little sad that I hadn't written even a short notice because I actually would like to help people. But without investigating further I would not have had an answer to your question. But...

I just came across the same problem and I found out why it happened. In short: You have to configure the networks correctly in your docker-compose-file.

You can use the ghost-mysql-repo as an example:

If the network is only defined for the webserver, it will not be in the default-network for the compose-file anymore, but the database will still be. So the webserver will not know about the database.

@jaceee
Copy link

jaceee commented Aug 3, 2017

For future reference:

When you specify the traefik network you're letting the container out of the default network, just add it to the networks too.

Example:

version: '3.1'

services:
  cache:
    restart: always
    image: redis:latest

  db:
    restart: always
    image: postgres:latest

  backend:
    restart: always
    image: whatever:latest
    links:
      - cache
      - db
    networks:
      - default # default network to be able to access cache and db
      - traefik
    labels:
      - "traefik.port=80"
      - "traefik.frontend.rule=Host:api.yggdrasil.dev"
      - "traefik.docker.network=traefik_default" # telling traefik which network to use to reach the container

networks:
  traefik:
    external:
      name: traefik_default

@nknapp
Copy link
Contributor

nknapp commented Oct 6, 2017

"For future reference" sounds like this should be an example in the README.md.
Who's up for a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants