realpython / orchestrating-docker

https://realpython.com/blog/python/dockerizing-flask-with-compose-and-machine-from-localhost-to-the-cloud/
465 stars 154 forks source link

Name resolution error when trying to create database #16

Open nmay231 opened 4 years ago

nmay231 commented 4 years ago

I've been following the instructions from your tutorial and everything has (mostly) been going fine. However, when I try to create the db with docker-compose run web /usr/local/bin/python create_db.py, it errors out with:

Traceback (most recent call last):
    ... MESS ...

psycopg2.OperationalError: could not translate host name "postgres" to address: Temporary failure in name resolution

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
    ... MESS ...

(If you need me to paste the full error, let me know)

I originally had docker-machine and docker-compose as the latest versions, but I downgraded to use the exact version in the tutorial.

$ # I am using Ubuntu 18.04
$ docker --version
Docker version 19.03.11, build 42e35e61f3
$ docker-machine --version
docker-machine version 0.16.1, build cce350d7
$ docker-compose --version
docker-compose version 1.23.2, build 1110ad01

Let me know what else you need from me and thanks for the awesome tutorial :+1:

kfrajer commented 4 years ago

I added the following modification in the docker-compose which solved this issue:

  postgres:
    restart: always
    image: postgres:latest
    environment:
      POSTGRES_HOST_AUTH_METHOD=trust
    ports:
      - "5432:5432"

Breaking change was reported in docker-library/postgres

nmay231 commented 4 years ago

Thanks @kfrajer! That fixed it after a little bit of finagling.

Note to other readers: I did have to list the environment variable as an array item: - POSTGRES_HOST_AUTH_METHOD=trust