3

I'm unable to get my Phoenix app connecting to the Postgres container when using docker-compose up.

My docker-compose.yml:

version: '3.5'

services:
  web:
    image: "solaris_cards:latest"
    ports:
      - "80:4000"
    env_file:
      - config/docker.env
    depends_on:
      - db

  db:
    image: postgres:10-alpine
    volumes:
      - "/var/lib/postgresql/data/pgdata/var/lib/postgresql/data"
    ports:
      - "5432:5432"
    env_file:
      - config/docker.env

The application running in web container complains that a connection to the Postgres container is non-existing:

[error] Postgrex.Protocol (#PID<0.2134.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (db:5432): non-existing domain - :nxdomain

My env variables:

DATABASE_HOST=db
DATABASE_USER=postgres
DATABASE_PASS=postgres

I have tried running the Postgres container first separately and then running the web container but still have the same problem.

If I change the database host to 0.0.0.0 (which is what Postgres shows when running), then it seems to connect but the connection is refused rather than not found.

However docker should be able to translate the host name with out me manually inputing the ip.

4
  • Try command getent hosts db from your web container (docker exec -it web sh), it should show the IP of your db container. If it does not, then there is an issue with name resolution, if it does, there may be an issue with the db container Commented Mar 8, 2019 at 9:31
  • @PierreB. I tried the command getent hosts db on my web container and it returned nothing. Commented Mar 8, 2019 at 10:01
  • Strange, I tried a similar version of your compose and it works: getent hosts db 172.23.0.2 db db Did you try down then up your compose? Commented Mar 8, 2019 at 10:34
  • 1
    @PierreB. After further digging I found the problem. Postgres container was exiting due to the volume already containing data. Was able to clear the volume with docker-compose down -v and that solved the problem. Thank you for your help. Commented Mar 11, 2019 at 1:46

1 Answer 1

1

Postgres was exiting due to its volume already containing data.

This was solved by cleaning the directory with:

docker-compose down -v
Sign up to request clarification or add additional context in comments.

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.