Bitbucket pipelines fails to build

I was trying to build my laravel project via butbucket pipelines. I get an error message when i try to run php artisan migrate command.
The error message is as follows.

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

my environment file is as follows.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=*****
DB_USERNAME=*****
DB_PASSWORD=*****

My bitbucket-pipelines.yml file is as follows

image: php:7.2-fpm

pipelines:
  default:
    - step:
        name: Build and test
        caches:
          - composer
        script:
          - apt-get update && apt-get install -qy git curl libmcrypt-dev mariadb-client ghostscript libzip-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev
          - yes | pecl install mcrypt-1.0.3
          - docker-php-ext-install pdo_mysql bcmath exif zip gd
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer install
          - cp -a .env.pipelines .env
          - php artisan config:clear
          - cat .env
          - php artisan migrate
          #- ./vendor/bin/phpunit
        services:
          - mysql
definitions:
  services:
    mysql:
      image: mysql:5.7
      environment:
        MYSQL_DATABASE: '****'
        MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
        MYSQL_USER: '****'
        MYSQL_PASSWORD: '****'
        MYSQL_ROOT_PASSWORD: '****'
        MYSQL_PORT: '3306'

Looks like the application is not able to communicate with mysql conainer.
Any ideas?
Thank you.

Source: Docker Questions

LEAVE A COMMENT