cyphos
cyphos

Reputation: 51

Gitlab-ci wit symfony : php_network_getaddresses: getaddrinfo failed: Name or service not known

I created gitlab-ci.yml with docker and symfony for the first time. I learn. I don't undertand whay it didn't work. I tried to change the name of the database. perhaps I forgot some things. I'm losing.

I need you for help to me. Thanks you a lot

This is error

$ php bin/console doctrine:database:drop --if-exists --force -e test
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known                         
In PDOConnection.php line 31:                                                                           
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known                                                          
In PDOConnection.php line 27:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known                                                          
In PDOConnection.php line 27:
                                                                           
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known                                                             
                 

This is gitlab-ci file

default:
  image: php:7.2-fpm
  services:
   - mysql:latest

cache:
  paths:
    - vendor/

variables:
  MYSQL_ROOT_PASSWORD: root
  MYSQL_DATABASE: sf4-reims

stages: # Ici on déclare toutes nos étapes
 - build
 - test

job:build:
 stage: build
 script:
   - apt-get update
   - curl -sSk https://getcomposer.org/installer | php -- --disable-tls &&
   - mv composer.phar /usr/local/bin/composer
   - composer install --prefer-dist
   - echo $CI_JOB_STAGE

job:test:
 stage: test
 script:
   - apt-get update
   - apt-get install -y git zip zip unzip
   - docker-php-ext-install pdo pdo_mysql
   - cp .env.test .env
   - php bin/console doctrine:database:drop --if-exists --force -e test
   - bin/console doctrine:database:create --if-not-exists -e test
   - bin/console doctrine:schema:drop --force --no-interaction -e test
   - bin/console doctrine:schema:create --no-interaction -e test
   - bin/console doctrine:fixtures:load --no-interaction --purge-with-truncate -vvv -e test
   - echo $CI_JOB_STAGE

This is file .env

 APP_ENV=test
 DATABASE_URL=mysql://root:root@database:3306/sf4-reims

This is file docker-compose.yml

     version: '3'
        services:
        apache:
            container_name: ${CONTAINER_NAME}_apache
            image: httpd:2.4.41
            ports:
                - ${APACHE_PORT}:80
                - ${APACHE_PORT_SSL}:443
            volumes:
                - ./${DIRECTORY_PROJECT}:/var/www/html
                - .docker/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
                - .docker/httpd/logs:/var/log/httpd
            depends_on:
                - php
            networks:
                - front-network
                - back-network

        database:
            image: mysql
            command: "--default-authentication-plugin=mysql_native_password"
            container_name: ${CONTAINER_NAME}_database
            volumes:
                - .docker/data/db:/var/lib/mysql
            environment:
                MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
                MYSQL_DATABASE: ${MYSQL_DATABASE}
                MYSQL_USER: ${MYSQL_USER}
                MYSQL_PASSWORD: ${MYSQL_PASSWORD}
            networks:
                - back-network

        php:
            build: .docker/php
            container_name: ${CONTAINER_NAME}_php
            volumes:
                - ./${DIRECTORY_PROJECT}:/var/www/html
                - .docker/php/php.ini:/usr/local/etc/php/php.ini
            environment:
                - maildev_host=${CONTAINER_NAME}_maildev
            depends_on:
    #            - maildev
                - database
            networks:
                - back-network

        phpmyadmin:
            image: phpmyadmin/phpmyadmin
            container_name: ${CONTAINER_NAME}_phpmyadmin
            environment:
              PMA_HOST: database
              PMA_PORT: ${MYSQL_PORT}
            ports:
                - ${PHPMYADMIN_PORT}:80
            links:
                - database
            networks:
                - back-network

Upvotes: 0

Views: 1712

Answers (1)

Máté Dusik
Máté Dusik

Reputation: 21

I know this was posted 9 months ago, but I believe I've just encountered the same problem, but could get it working by adding alias to the mysql service in the gitlab-ci.yml.

I can see you "index" your mysql container database in the docker-compose.yml, so I believe your application references the mysql host as database in your application configuration (config/packages/doctrine.yaml doctrine.dbal.host). In this case, you should write

default:
  image: php:7.2-fpm
  services:
   - name: mysql:latest
     alias: database

instead of

default:
  image: php:7.2-fpm
  services:
   - mysql:latest

in your gitlab-ci.yml. In case you use another name in your host settings, then you should use that as an alias.

Upvotes: 2

Related Questions