使用php和mysql创建docker镜像

时间:2017-01-03 11:20:51

标签: php mysql docker gitlab-ci

我在ubuntu和 mysql:5.6 image 上构建了 php5.6-apache image 。我想从上面的两个图像创建docker图像,以便我可以在 gitlab ci 中使用新构建的图像。我怎样才能做到这一点?我对docker和gitlab相当新。

我在gitlab中尝试过,但没有用。

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

在gitlab ci中运行composer install时出现以下错误。

[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)

1 个答案:

答案 0 :(得分:2)

您没有正确配置数据库。使用您的配置,mysql可在主机mysql和端口3306上使用。相反,您的应用程序正在通过unix套接字尝试本地连接。配置连接,一切都应该有效。