openfrontier / docker-gerrit

Build a Docker image with the Gerrit code review system
Apache License 2.0
197 stars 116 forks source link

Problem with postgres password #7

Closed zagrev closed 9 years ago

zagrev commented 9 years ago

I am trying to use openfrontier/gerrit:latest -> 2.11.2 with an existing postgres database. Since the database already exists (in a container called postgres), I just created a user/pw gerrit2/gerrit in the database

CREATE USER gerrit2 PASSWORD gerrit; CREATE DATABASE gerrit2 OWNER gerrit2 LOGIN;

and started up the gerrit container with this command line:

sudo docker run --detach \ --restart always \ --name gerrit \ --link postgres:db \ -p 8200:8080 \ -p 29418:29418 \ -e WEBURL=http://gerrit.XXXXXX.com \ -e DATABASE_TYPE=postgresql \ -v /srv/gerrit:/var/gerrit/review_site:Z \ openfrontier/gerrit

But I am getting this in the gerrit logs:

fatal: DbInjector failed fatal: Unable to determine SqlDialect fatal: caused by org.postgresql.util.PSQLException: FATAL: password authentication failed for user "gerrit2"

And this in the postgres logs:

FATAL: password authentication failed for user "gerrit2" DETAIL: Connection matched pg_hba.conf line 95: "host all all 0.0.0.0/0 md5"

So the two containers are talking correctly.

This looks like the password is wrong. I have also tried with password gerrit2 without success. Can you tell me the password to use? Perhaps you can make the postgres user and password configurable?

thinkernel commented 9 years ago

There are basically three environment variables involved in database connection from gerrit to postgresql. The DB_ENV_POSTGRES_DB specifies which database to be connected. The DB_ENV_POSTGRES_USER and DB_ENV_POSTGRES_PASSWORD specify the user name and password. These variables can be created automatically in gerrit container by --link postgres:db if POSTGRES_DB, POSTGRES_USER and POSTGRES_PASSWORD are defined in the postgres container which is what I recommend in the README. Since you are using an existing postgres container which means those three environment variables may be occupied by another existing database or even not existed at all. You can check it by execute docker exec postgres env. In this case you can define these environment variables as the docker run options like: docker run \ --link postgres:db \ -e DATABASE_TYPE=postgresql \ -e DB_ENV_POSTGRES_DB=gerrit2 \ -e DB_ENV_POSTGRES_USER=gerrit2 \ -e DB_ENV_POSTGRES_PASSWORD=gerrit \ .... You can reference [Section database] in gerrit-entrypoint.sh if you want to know how these variables are used to define gerrit.config file.

zagrev commented 9 years ago

Thanks! After reading the Docker documentation on --link it makes much more sense.