1

I'm trying to get a setup going with a webservice that consumes a postgres database. Should be simple to setup, but I'm getting errors. So, first thing I want to make sure is that the database I set up is actually there and running.

To test this I substitute the "consumer" or "client" for an alpine interactive shell like so:

version: '3'
services:

  db:
    image: postgres:10.1-alpine
    container_name: db
    expose:
      - 5432
    volumes:
      - "dbdata:/var/lib/postgresql/data"
    environment:
      - POSTGES_USER=user
      - POSTGRES_PASSWORD=pass
      - POSTGRES_DB=db

  web:
    image: alpine:latest
    stdin_open: true
    tty: true
    entrypoint: /bin/sh
    depends_on:
      - db

volumes:
  dbdata:

Then I run the following command to get into the interactive shell:

docker-compose run web

and the following command to get in the database:

apk --update add postgresql-client && rm -rf /var/cache/apk/*

psql -h db -U user db

I get a plain denial from postgresql:

psql: FATAL:  password authentication failed for user "user"

Same error message for each combo of username/password/databasename I try. Not much helpful.

What am I doing wrong here?

1 Answer 1

5

You have a typo in your docker-compose file. You mispelled POSTGRES here:

POSTGES_USER=user

That means the user user isn't being created. If I correct that typo, so that I have:

version: '3'
services:

  db:
    image: postgres:10.1-alpine
    expose:
      - 5432
    volumes:
      - "dbdata:/var/lib/postgresql/data"
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=pass
      - POSTGRES_DB=db

  web:
    image: alpine:latest
    stdin_open: true
    tty: true
    entrypoint: /bin/sh
    depends_on:
      - db

volumes:
  dbdata:

Start the environment:

docker-compose up -d

Attach to the web contained and install the postgresql client:

$ docker attach project_web_1
/ # apk add --update postgresql-client

Then I can connect without a problem:

/ # psql -h db -U user db
Password for user user:
psql (11.2, server 10.1)
Type "help" for help.

db=#
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.