admin管理员组

文章数量:1396746

I have a docker container running a postgresql database. When i access the container (docker exec -it my-docker) and then try to connect to my database(psql -U myuser) and type my password the connection works.

But then wwhen i try the command psql -h localhost -p 5432 -U myuser and type my same password i get an error.

Does anyone know what can be the problem here?

Needed Information

OS : Windows 10 Pro

Tools: Docker Desktop

Error: psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "myuser"

docker-compose.yml:


services:
  postgres:
    image: postgres:15
    container_name: mycontainer
    restart: always
    environment:
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypass
      POSTGRES_DB: mydb
    ports:
      - "5432:5432"
    networks:
      - mynetwork
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:

networks:
  mynetwork:
    driver: bridge`

pg_hba.conf:


# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

host all all all scram-sha-256

postgresql.conf:

# PostgreSQL configuration file
# -----------------------------
#------------------------------------------------------------------------------       
# FILE LOCATIONS
#------------------------------------------------------------------------------       
#------------------------------------------------------------------------------       
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------       
# - Connection Settings -
listen_addresses = '*'
#port = 5432                            # (change requires restart)
max_connections = 100                   # (change requires restart)
#------------------------------------------------------------------------------       
# RESOURCE USAGE (except WAL)
#------------------------------------------------------------------------------       
# - Memory -
shared_buffers = 128MB                  # min 128kB
dynamic_shared_memory_type = posix      # the default is usually the first option     
#------------------------------------------------------------------------------       
# WRITE-AHEAD LOG
#------------------------------------------------------------------------------       
max_wal_size = 1GB
min_wal_size = 80MB
#------------------------------------------------------------------------------       
# REPLICATION
#------------------------------------------------------------------------------       
#------------------------------------------------------------------------------       
# QUERY TUNING
#------------------------------------------------------------------------------       
#------------------------------------------------------------------------------       
# REPORTING AND LOGGING
#------------------------------------------------------------------------------       
log_timezone = 'Etc/UTC'
#------------------------------------------------------------------------------       
# PROCESS TITLE
#------------------------------------------------------------------------------       
#------------------------------------------------------------------------------       
# STATISTICS
#------------------------------------------------------------------------------       
#------------------------------------------------------------------------------       
# CLIENT CONNECTION DEFAULTS
#------------------------------------------------------------------------------       

# - Locale and Formatting -
datestyle = 'iso, mdy'
timezone = 'Etc/UTC'
lc_messages = 'en_US.utf8'                      # locale for system error message     
lc_monetary = 'en_US.utf8'                      # locale for monetary formatting      
lc_numeric = 'en_US.utf8'                       # locale for number formatting        
lc_time = 'en_US.utf8'                          # locale for time formatting
default_text_search_config = 'pg_catalog.english'

本文标签: Cannot connect to my PostgreSQL Docker Database from my Windows EnvironmentStack Overflow