title: GitLab CI with docker and laravel cannot connect to database
body: <p>I have Gitlab CI set-up but it keeps failing when trying to run the database migrations:</p>
  
  <pre><code>SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = test_db and table_name = migrations)    
  </code></pre>
  
  <p>My gitlab.yml file is:</p>
  
  <pre><code>before_script:
    - bash .gitlab-ci.sh
    - export APP_ENV=testing
  
  services:
    - mysql:8.0
  
  variables:
    MYSQL_DATABASE: test_db
    MYSQL_ROOT_PASSWORD: testdb
    DB_HOST: mysql
    DB_USERNAME: root
    DOCKER_DRIVER: overlay
  
  cache:
    paths:
    - vendor/
    - node_modules/
  
  stages:
    - test
    - deploy
  
  phpunit:php7.1:mysql8.0:
    stage: test
    image: php:7.1
    services:
      - mysql:8.0
    script:
      - echo "Running PHP Unit - php 7.1 mysql 8.0"
      - php vendor/bin/phpunit --colors
  
  deploy_production:
    stage: deploy
    script:
      - 'which ssh-agent || ( apt-get update -y &amp;&amp; apt-get install openssh-client -y )'
      - eval $(ssh-agent -s)
      - ssh-add &lt;(echo "$SSH_PRIVATE_KEY")
      - mkdir -p ~/.ssh
      - '[[ -f /.dockerenv ]] &amp;&amp; echo -e "Host *\n\tStrictHostKeyChecking no\n\n" &gt; ~/.ssh/config'
  
      - ~/.composer/vendor/bin/envoy run deploy
    environment:
      name: production
      url: http://167.99.202.64
  
    when: manual
    only:
      - master
  </code></pre>
  
  <p>My before bash script is as follows:</p>
  
  <pre><code>#!/bin/bash
  
  # Install dependencies only for Docker.
  [[ ! -e /.dockerinit ]] &amp;&amp; [[ ! -e  /.dockerenv ]] &amp;&amp; exit 0
  set -xe
  
  # Update packages and install composer and PHP dependencies.
  apt-get update -yqq
  apt-get install git libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq
  
  # Compile PHP, include these extensions.
  docker-php-ext-install mbstring mcrypt pdo_mysql curl json intl gd xml zip bz2 opcache
  
  # Install Composer and project dependencies
  echo 'Installing composer'
  curl -sS https://getcomposer.org/installer | php
  php composer.phar install --no-plugins --no-scripts --dev
  
  # Copy over testing configuration.
  cp .env.testing .env
  
  # Generate an application key. Re-cache
  php artisan key:generate
  php artisan config:cache
  
  # Run database migrations
  php artisan migrate
  </code></pre>
  
  <p>Finally my env.testing file:</p>
  
  <pre><code>APP_ENV=testing
  APP_DEBUG=true
  APP_KEY=key
  
  DB_HOST=mysql
  DB_DATABASE=test_db
  DB_USERNAME=root
  DB_PASSWORD=testdb
  
  CACHE_DRIVER=array
  SESSION_DRIVER=array
  QUEUE_DRIVER=sync
  MAIL_DRIVER=log
  </code></pre>
  
  <p>I'm guessing Laravel inside the PHP7.1 container can't see the MySQL container looking at the error message? Is declaring it as a service in the gitlab.yml not enough?</p>