GitLab设置使用官方PostgreSQL和GitLab docker容器无法正常工作

时间:2017-08-21 17:54:17

标签: postgresql docker gitlab

我正在尝试使用单独的docker容器为GitLab和PostgreSQL设置GitLab。我正在使用RancherOS v1.0.3并启用了Kubernetes。现在,我想要的是拥有两个容器的单个节点。稍后,我将研究在不同的节点上配置它们。

[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

现在,当我运行PostgreSQL容器并尝试登录时,我会收到错误。

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

似乎尚未创建db(gitlabhq_production)。

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)

尽管传递参数,为什么不创建数据库?

更新:

PostgreSQL容器日志:

[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/*
...
... 

1 个答案:

答案 0 :(得分:2)

您使用的是错误的环境变量名称:

DB_NAME应为POSTGRES_DB

DB_USER应为POSTGRES_USER

DB_PASS应为POSTGRES_PASSWORD

检查https://hub.docker.com/_/postgres/