Postgresql – authentication failed in Docker

Im trying to run postgresql in my Docker container.

Here is my DockerFile for postgresql

  • How to do host-specific customization on docker images
  • Hitting resources in a private network from within a Docker container using VPN
  • Docker: failed to pull image (oversized record received with length 20527
  • Consistent hostname for Docker containers/VM across platforms?
  • How can i run rethinkdb-dump/export in RethinkDB + Docker
  • Incrementally build Docker image hierarchy with Makefile
  • 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?

  • how to mount a Host volume to node.js docker container
  • NginX as HTTPS reverse proxy for multiple sub-domains?
  • Location on Host VM that can be accessed by docker containers
  • dokku error: cannot find entity for app
  • Read local file system with Java from Docker container
  • Mounting a single file from a Docker data volume in a Docker
  • 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.