openfrontier / docker-gerrit

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

Can't start gerrit/postgres using composefile #18

Closed wilfriedroset closed 8 years ago

wilfriedroset commented 8 years ago

When using a composefile to start postgres/gerrit, I end up with caused by java.net.UnknownHostException: pg-gerrit .

version: '2'
volumes:
    pg_data:
    gerrit_data:
services:
# docker run --name pg-gerrit -p 5432:5432 -e POSTGRES_USER=gerrit2 -e POSTGRES_PASSWORD=gerrit -e POSTGRES_DB=reviewdb -d postgres
    db:
        container_name: 'pg-gerrit'
        image: 'postgres:9.5.3'
        restart: always
        ports:
            - '5432:5432'
        environment:
            POSTGRES_USER: gerrit2
            POSTGRES_PASSWORD: gerrit
            POSTGRES_DB: reviewdb
        volumes:
            - '/etc/localtime:/etc/localtime:ro'
            - 'pg_data:/var/lib/postgresql/data'
# docker run --name gerrit --link pg-gerrit:db -p 8080:8080 -p 29418:29418 -e DATABASE_TYPE=postgresql -d openfrontier/gerrit
    gerrit:
        container_name: 'gerrit'
        image: 'openfrontier/gerrit:2.11.x'
        restart: always
        ports:
            - '8080:8080'
            - '29418:29418'
        environment:
            DATABASE_TYPE: postgresql
            DB_PORT_5432_TCP_ADDR: pg-gerrit
        volumes:
            - '/etc/localtime:/etc/localtime:ro'
            - 'gerrit_data:/var/gerrit/review_site'

Docker images

$ docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
openfrontier/gerrit   alpine              6dbf2c7fddff        5 days ago          230.5 MB
openfrontier/gerrit   2.11.x              6d3885aeedf7        5 days ago          419.2 MB
postgres              9.5.3               7ee9d2061970        2 weeks ago         275.2 MB
openfrontier/gerrit   2.9.x               8250fb51ffa7        4 months ago        427.4 MB

Docker info

$ docker-compose --version
docker-compose version 1.7.1, build 0a9ab35
$ docker info
Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 69
Server Version: 1.11.1
Storage Driver: devicemapper
 Pool Name: docker-253:0-208896927-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 107.4 GB
 Backing Filesystem: xfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 1.725 GB
 Data Space Total: 107.4 GB
 Data Space Available: 44.11 GB
 Metadata Space Used: 3.871 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.144 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Deferred Deletion Enabled: false
 Deferred Deleted Device Count: 0
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 WARNING: Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.107-RHEL7 (2015-10-14)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge null host
Kernel Version: 3.10.0-327.3.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.605 GiB
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

Error

docker-compose up
Creating volume "gerrithub_gerrit_data" with default driver
Creating pg-gerrit
Creating gerrit
Attaching to gerrit, pg-gerrit
gerrit    | First time initialize gerrit...
pg-gerrit | LOG:  database system was shut down at 2016-06-30 14:29:51 CEST
pg-gerrit | LOG:  MultiXact member wraparound protections are now enabled
pg-gerrit | LOG:  database system is ready to accept connections
pg-gerrit | LOG:  autovacuum launcher started
gerrit    | [2016-06-30 12:30:52,271] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /var/gerrit/review_site/etc/gerrit.config; assuming defaults
gerrit    | Generating SSH host key ... rsa(simple)... done
gerrit    | Initialized /var/gerrit/review_site
gerrit    |
gerrit    | /gerrit-entrypoint.sh: ignoring /docker-entrypoint-init.d/*
gerrit    |
gerrit    | Upgrading gerrit...
gerrit    | fatal: DbInjector failed
gerrit    | fatal: Unable to determine SqlDialect
gerrit    | fatal:   caused by org.postgresql.util.PSQLException: The connection attempt failed.
gerrit    | fatal:   caused by java.net.UnknownHostException: pg-gerrit
gerrit exited with code 0

Note: you might see the init of postgres the first time.

I don't get the error when running the two docker run manually or with different images. I think that tere is something wrong about the docker-compose file but I can't point the error. Any idea where I've done something wrong ?

thinkernel commented 8 years ago

How to define a container link between gerrit & pg-gerrit like --link pg-gerrit:db in compose? DB_PORT_5432_TCP_ADDR: pg-gerritmight not be a good idea to link gerrit to the database.

wilfriedroset commented 8 years ago

I've added the link between my two containers. According to the documentation it should be done with the directive links. I've updated my composefile using envvar replaced by gerrit-entrypoint.sh to get it running

version: '2'
volumes:
    pg_data:
    gerrit_data:
services:
# docker run --name pg-gerrit -p 5432:5432 -e POSTGRES_USER=gerrit2 -e POSTGRES_PASSWORD=gerrit -e POSTGRES_DB=reviewdb -d postgres
    pg-gerrit:
        container_name: 'pg-gerrit'
        image: 'postgres:9.5.3'
        #restart: always
        ports:
            - '5432:5432'
        environment:
            POSTGRES_USER: gerrit2
            POSTGRES_PASSWORD: gerrit
            POSTGRES_DB: reviewdb
        volumes:
            - '/etc/localtime:/etc/localtime:ro'
            - 'pg_data:/var/lib/postgresql/data'
# docker run --name gerrit --link pg-gerrit:db -p 8080:8080 -p 29418:29418 -e DATABASE_TYPE=postgresql -d openfrontier/gerrit
    gerrit:
        container_name: 'gerrit'
        image: 'openfrontier/gerrit:2.11.x'
        #restart: always
        ports:
            - '8080:8080'
            - '29418:29418'
        environment:
            DATABASE_TYPE: postgresql
            DB_ENV_POSTGRES_DB: reviewdb
            DB_ENV_POSTGRES_PASSWORD: gerrit
            DB_ENV_POSTGRES_USER: gerrit2
            DB_PORT_5432_TCP_ADDR: db
        links:
            - pg-gerrit:db
        volumes:
            - '/etc/localtime:/etc/localtime:ro'
            - 'gerrit_data:/var/gerrit/review_site'

Without _DB_ENV_POSTGRESDB, _DB_ENV_POSTGRESPASSWORD, _DB_PORT_5432_TCPADDR variables I can't start gerrit container.

Without _DB_ENV_POSTGRESDB, I've got

gerrit       | fatal: DbInjector failed
gerrit       | fatal: Unable to determine SqlDialect
gerrit       | fatal:   caused by org.postgresql.util.PSQLException: FATAL: database "db" does not exist

The configuration file generated looks like:

[database]
    type = postgresql
    database = db/ReviewDB
    hostname = db
    username = gerrit2

Without _DB_ENV_POSTGRESPASSWORD, I've got:

gerrit       | fatal: DbInjector failed
gerrit       | fatal: Unable to determine SqlDialect
gerrit       | fatal:   caused by org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided.

The configuration file generated looks like:

[database]
    type = postgresql
    database = reviewdb
    hostname = db
    username = gerrit2

Without _DB_PORT_5432_TCPADDR, I've got:

gerrit       | fatal: DbInjector failed
gerrit       | fatal: Unable to determine SqlDialect
gerrit       | fatal:   caused by org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
gerrit       | fatal:   caused by java.net.ConnectException: Connection refused

The configuration file generated looks like:

grep database -A4 /var/lib/docker/volumes/gerrit_gerrit_data/_data/etc/gerrit.config 
[database]
    type = postgresql
    database = reviewdb
    username = gerrit2
    hostname = localhost
thinkernel commented 8 years ago

The link environment variables reference is deprecated in version 2 of compose. So you have to define them in the compose file. But link is necessary unless you're using docker network. It seems that I'll have to think about how to support docker network in this image.

thinkernel commented 8 years ago

@wilfriedroset Here is an example I made recently to show the way of utilizing docker-compose, docker network and docker volume. It may be a helpful reference for this issue. Please let me know if your issue is solved then I can close this one.

wilfriedroset commented 8 years ago

Well detail compose file. Thanks!