I have set up the following docker-compose.yml file to set up and run PostgreSQL and PgAdmin.
version: '3.1'
services:
  db:
    image: postgres:latest
    container_name: postgres-dopp
    restart: unless-stopped
    environment:
      POSTGRES_USER: dopp_dev
      POSTGRES_PASSWORD: dopp_dev_pass
      PGDATA: /data/postgres
    ports:
      - "5432:5432"
    volumes:
      - dbdata-dopp:/data/postgres
    networks:
      - network-dopp
  pgadmin:
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: admin
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    depends_on:
      - db
    volumes:
      - dbdata-dopp:/data/pgadmin
    ports:
      - "5050:80"
    networks:
      - network-dopp
networks:
  network-dopp:
    driver: bridge
volumes:
  dbdata-dopp:
    name: dopp-db-data
    driver: local
This works fine, insofar as I can navigate to PgAdmin in my host machine's browser and through that I can connect to the database using the credentials I've defined in the environment variables. However, when attempting to make a direct connection to the postgres database from my host machine (by connecting to localhost:5432, since I have configured to expose that port), I then get the following error response:
[28P01] FATAL: password authentication failed for user "dopp_dev"
I'm fairly new to the peculiarities of Postgres and docker configuration, so I'm not sure what is causing Postgres to say that password authentication fails when connecting from my host machine, while it works perfectly fine if I do it through PgAdmin, which is on the same internal docker network.
