Postgresql – authentication failed in Docker

Im trying to run postgresql in my Docker container.

Here is my DockerFile for postgresql

  • exec not found using Dockerfile ENTRYPOINT
  • Docker on AWS. ECS or Docker Datacenter
  • Backing up and restoring mysql database with Laravel/Docker
  • ZMQ crashes “randomly” in aiohttp web service
  • How to run sql script for postgres in docker
  • Can I mount a windows network path inside docker without -v option?
  • FROM postgres:9.5.2
    
    RUN localedef -i ru_RU -c -f UTF-8 -A /usr/share/locale/locale.alias ru_RU.UTF-8
    ENV LANG ru_RU.utf8
    
    ENV POSTGRES_PASSWORD OaO1OHrzTZ3cqyLnju2z
    ENV PROJECT_USER test
    ENV PROJECT_DATABASE test
    
    COPY config/init-user-db.sh /docker-entrypoint-initdb.d/init-user-db.sh
    

    init-user-db.sh

    #!/bin/bash
    set -e
    
    psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
        CREATE EXTENSION "adminpack";
        CREATE EXTENSION "autoinc";
        CREATE EXTENSION "cube";
        CREATE EXTENSION "file_fdw";
        CREATE EXTENSION "fuzzystrmatch";
        CREATE EXTENSION "hstore";
        CREATE EXTENSION "insert_username";
        CREATE EXTENSION "intarray";
        CREATE EXTENSION "isn";
        CREATE EXTENSION "lo";
        CREATE EXTENSION "ltree";
        CREATE EXTENSION "moddatetime";
        CREATE EXTENSION "pageinspect";
        CREATE EXTENSION "pgcrypto";
        CREATE EXTENSION "pg_trgm";
        CREATE EXTENSION "postgres_fdw";
        CREATE EXTENSION "refint";
        CREATE EXTENSION "seg";
        CREATE EXTENSION "sslinfo";
        CREATE EXTENSION "tablefunc";
        CREATE EXTENSION "tcn";
        CREATE EXTENSION "timetravel";
        CREATE EXTENSION "unaccent";
        CREATE EXTENSION "uuid-ossp";
        CREATE EXTENSION "xml2";
        CREATE USER "$PROJECT_USER" WITH password 'OaO1OHrzTZ3cqyLnju2z
    ';
        CREATE DATABASE "$PROJECT_DATABASE" WITH OWNER="$PROJECT_USER" TEMPLATE=template1 ;
        GRANT ALL PRIVILEGES ON DATABASE "$PROJECT_DATABASE" TO "$PROJECT_USER";
        REVOKE ALL PRIVILEGES ON DATABASE "$PROJECT_DATABASE" FROM PUBLIC;
    EOSQL
    

    thats whats in my application configs (symfony 3)

    parameters:
        database_host: 192.168.99.100
        database_port: 48002
        database_name: test
        database_user: test
        database_password: OaO1OHrzTZ3cqyLnju2z
        mailer_transport: smtp
        mailer_host: 127.0.0.1
        mailer_user: null
        mailer_password: null
        secret: O81s4KSjs8NdxSAacvU82AdC973aSxKdL
    

    As you see, i have in every place the same password – OaO1OHrzTZ3cqyLnju2z.

    But im getting error password authentication failed for user “test”.

    What is missing? Why it doesnt authenticate?

  • Run DDL-script generated by Entity Framework does not create tables in Docker container
  • Machine created as normal user isn't visible for administrator
  • How to start a Docker container with cloud-config file for CoreOS?
  • “docker run swarm create” failed with error “503 Service Unavailable”
  • Rancher: NFS or convoy-nfs?
  • How can I configure environment variables on a Docker container without hard-coding them in the Dockerfile? [closed]
  • One Solution collect form web for “Postgresql – authentication failed in Docker”

    Did you paste the script directly from the source?
    Because it looks like you have a space between the last digit on your password and the quote :

        CREATE USER "$PROJECT_USER" WITH password 'OaO1OHrzTZ3cqyLnju2z
    ';
    

    Try

    CREATE USER "$PROJECT_USER" WITH password 'OaO1OHrzTZ3cqyLnju2z';
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.