Gitlab CI,Symfony + Postgres错误连接被拒绝

时间:2019-07-02 12:15:55

标签: postgresql symfony docker gitlab gitlab-ci

使用doctine创建架构时出现错误

$ php bin/console doctrine:schema:create --env=test

In AbstractPostgreSQLDriver.php line 73:

  An exception occurred in driver: SQLSTATE[08006] [7] could not connect to s  
  erver: Connection refused                                                    
    Is the server running on host "127.0.0.1" and accepting                     
    TCP/IP connections on port 5432?      

和我的gitlab-ci.yml

database:
  stage: building
  services:
    - postgres:10
  variables:
    POSTGRES_DB: back
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: ''
    POSTGRES_HOST: postgres
    POSTGRES_PORT: 5432
  before_script:
    # Install pdo_pgsql driver
    - apt-get update
    - apt-get install -y libpq-dev
    - docker-php-ext-install pdo_pgsql
  script:
    - php bin/console doctrine:schema:create --env=test
    - php -d memory_limit=2048M bin/console --env=test cache:warmup --no-debug

还有我的gitlab-parameters.yml(在app / config / parameters.yml上是cp)

parameters:
    database_host: postgres
    database_port: 5432
    database_name: back
    database_user: postgres
    database_password: ''

其他信息:

当我尝试创建数据库时,我收到了来自gitlab-ci的好消息

$ php bin/console doctrine:database:create --env=test
Could not create database "back" for connection named default
An exception occurred while executing 'CREATE DATABASE "back"':

SQLSTATE[42P04]: Duplicate database: 7 ERROR:  database "back" already exists

版本:

php 7.2.19
神秘主义者3.4

和我的config_text.yml

imports:
    - { resource: config_dev.yml }

framework:
    test: ~
    session:
        storage_id: session.storage.mock_file
    profiler:
        collect: false

web_profiler:
    toolbar: false
    intercept_redirects: false

swiftmailer:
    disable_delivery: true

如何解决?

编辑:

postgres没有运行:

netstat -plntu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -

0 个答案:

没有答案