Gitlab CI和Docker在迁移时抛出错误

时间:2015-12-03 04:23:00

标签: laravel docker gitlab-ci

我正在尝试使用GitLab CI和Docker运行PHPUnit测试。但是,当它到达我正在运行迁移时,我收到此错误:

$ php artisan migrate



  [PDOException]                                    
  SQLSTATE[HY000] [2002] No such file or directory  




ERROR: Build failed with: exit code 1

这是我的.gitlab-ci.yml文件:

# Before Script
before_script:
    - composer self-update
    - composer config -g github-oauth.github.com $GITHUB_AUTH_KEY
    - composer install --prefer-dist
    - cp .env.example .env
    - echo "DB_HOST=mysql" >> .env
    - echo "CHALLONGE_API=$CHALLONGE_API" >> .env
    - echo "CHALLONGE_SUBDOMAIN=$CHALLONGE_SUBDOMAIN" >> .env
    - echo "EBOT_DB_PASSWORD=$EBOT_DB_PASSWORD" >> .env
    - echo "SOCKET_IO_IP=$SOCKET_IO_IP" >> .env
    - echo "REDIS_HOST=$REDIS_HOST" >> .env 
    - php artisan key:generate
    - php artisan migrate

# Services
services:
    - mysql:lastest
    - redis:latest

# Variables
variables:
    MYSQL_USER: homestead
    MYSQL_PASSWORD: secret
    MYSQL_ROOT_PASSWORD: secret
    MYSQL_DATABASE: $DB_NAME

# PHP 5.6
php:5.6:
  image: bobey/docker-gitlab-ci-runner-php5.6
  script:
    - echo "Running PHPUnit Tests"
    - php vendor/bin/phpunit --colors --debug  --coverage-text

为什么会抛出这个错误?

1 个答案:

答案 0 :(得分:1)

我认为.env文件中的DB_HOST设置为localhost,它将尝试通过unix套接字连接到MySql服务器。但是,开箱即用不支持。请尝试在测试环境中将其设置为mysql,如文档中所述:http://docs.gitlab.com/ee/ci/services/mysql.html