0

I am trying to setup GitLab using separate docker containers for both GitLab and PostgreSQL. I am using RancherOS v1.0.3 with Kubernetes enabled. For now, all i want is to have a single node having both the containers. Later, i will look into configuring them on separate nodes.

[rancher@rancher-agent-2 ~]$ cat postgresql.sh
docker run --name=postgresql -d \
    --env 'DB_NAME=gitlabhq_production' \
    --env 'DB_USER=gitlab' --env 'DB_PASS=password' \
    --env 'DB_EXTENSION=pg_trgm' \
    --volume /opt/postgresql:/var/lib/postgresql \
    postgres:9.6.3

[rancher@rancher-agent-2 ~]$ cat gitlab.sh
docker run --name=gitlab -d --link postgresql:postgresql \
  -v /opt/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:9.3.9-ce.0

Now when i run the PostgreSQL container and try logging in, i get errors.

[rancher@rancher-agent-2 ~]$ docker exec -it postgresql bash
root@a6cef780c594:/# psql -d gitlabhq_production -U gitlab
psql: FATAL:  role "gitlab" does not exist

Seems the db (gitlabhq_production) has not been created.

root@a6cef780c594:/# psql -U postgres
psql (9.6.3)
Type "help" for help.

postgres=# \l
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
-----------+----------+----------+------------+------------+-----------------------
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
(3 rows)

Why is it not creating the db despite passing the parameters?

UPDATE:

PostgreSQL container log:

[rancher@rancher-agent-2 ~]$ docker logs postgresql
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
...
... 
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
 done
server started
ALTER ROLE


/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
...
... 
2
  • What does the beginning of the postgresql container log say? Commented Aug 22, 2017 at 6:08
  • Please check UPDATE Commented Aug 22, 2017 at 6:28

1 Answer 1

2

You are using the wrong environment vars names:

DB_NAME should be POSTGRES_DB

DB_USER should be POSTGRES_USER

DB_PASS should be POSTGRES_PASSWORD

Check https://hub.docker.com/_/postgres/

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you! :) Did you get the clue from the UPDATE section or you just noticed the script i mentioned? I can now see the db and user created. Any idea what to use for DB_EXTENSION? POSTGRES_EXTENSION didn't work. :(
No, I just read your docker run again and noticed the error. There is no POSTGRES_EXTENSION env var, but you can either provide a custom SQL to be executed at startup (check the How to extend this image section in the link I posted above) or just initialize the extension by hand once the container spawns up if that suits your needs.
Adding custom script seems better. So adding this custom script will add one more layer to this container, correct?
no, that sql script is executed at run time, so there is no additional layer (layers are added at compile time, so if you create a Dockerfile inheriting from postgres image and adding a file into the correct path with the COPY command, that would lead to a new layer.)
As a personal point of view about storage management on k8s, I'd install postgresql as a standalone, traditional service in one external host or use an hosted solution (depends on your provider of choice). As per your question, I usually put inside the image only the configuration stuff. In your case, the db extension is not a configuration of postgresql itself, but a setup of the database instance. In this case I'd just proceed by hand (so not creating a custom image). But I guess this is a personal choice in this case.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.