1

I have php5.6-apache image built on ubuntu and mysql:5.6 image. I want to create docker image from above two images so that I can use newly built image in gitlab ci. How can I do that? I am fairly new to docker and gitlab.

I tried following in gitlab, but didn't work.

image: viraths/php5.6-apache:latest

stages:
  - build
  - test

deps build:
  stage: build
  variables:
    MYSQL_DATABASE: test
    MYSQL_ROOT_PASSWORD: password
    DNSDOCK_ALIAS: localhost
  services:
    - mysql:5.6
  script:
    - export APPLICATION_ENV=test
    - if [ -f /.dockerinit ]; then export COMPOSER_HOME=/cache/composer; fi;
    - php -v
    - composer install --no-progress --no-interaction --prefer-dist
  artifacts:
    paths:
      - vendor/
    expire_in: 1 week
  tags:
    - docker

I got following error when running composer install in gitlab ci.

[Doctrine\DBAL\Exception\ConnectionException]                                
An exception occured in driver: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Viraths
  • 840
  • 1
  • 13
  • 23

1 Answers1

2

You didn't configure the database properly. With your configuration mysql is available on host mysql and port 3306. Instead your application is trying a local connection thru a unix socket. Configure the connection and all should work.

Jakub Kania
  • 15,665
  • 2
  • 37
  • 47
  • Can you please provide me an example. – Viraths Jan 03 '17 at 12:12
  • No, I'm afraid I can't tell you how to change the configuration of an application I haven't seen. I guess you use Symfony so just follow the guide: https://symfony.com/doc/current/doctrine.html Otherwise just grep for host. – Jakub Kania Jan 03 '17 at 12:21
  • Thanks man, that worked. I just changed my parameters.yml.dist file as follows. parameters: database_host: mysql database_port: 3306 – Viraths Jan 03 '17 at 12:39