2015-11-30 52 views
0

我试图在我的gitlab ci服务器上运行moodle phpunit。使用gitlab-ci.yml文件,我使用php 5.6和mysql服务创建了一个容器。如何在mysql docker服务上创建数据库

# Services 
services: 
    - mysql:latest 

before_script: 
    - mysql -e 'CREATE DATABASE gitlab_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ; 

我得到ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2),不知道如何继续。

+0

的http://计算器。 com/a/15039113 – Drew

+0

[ERROR 2002(HY000):无法通过套接字'/var/run/mysqld/mysqld.sock'(2)]连接到本地MySQL服务器(http://stackoverflow.com/questions/11657829/error-2002-hy000 -cant-connect-to-local-mysql-server-through-socket-var-run) – Drew

+1

命令i产生的错误n before_script还是工作本身?由于'mysql'服务位于另一个容器中,因此可能需要使用'mysql --host = mysql -e'CREATE ...'。 – yjwong

回答

0

托马斯这是我gitlab-ci.yml文件,你需要这样的事情:

# Select image from https://hub.docker.com/r/_/php/ 
image: php:7.0.0 

services: 
    - mysql:5.7 

variables: 
    # Configure mysql environment variables (https://hub.docker.com/r/_/mysql/) 
    MYSQL_DATABASE: symfony 
    MYSQL_ROOT_PASSWORD: qwerty 

# Composer stores all downloaded packages in the vendor/ directory. 
# Do not use the following if the vendor/ directory is commited to 
# your git repository. 
cache: 
    paths: 
    - vendor/ 

before_script: 
# Install dependencies 
- bash ci/docker_install.sh > /dev/null 
- cp ci/parameters.yml app/config/parameters.yml 
- composer install 

test:app: 
    script: 
    - phpunit 

这是我的CI文件夹内docker_install.sh

#!/bin/bash 

# We need to install dependencies only for Docker 
[[ ! -e /.dockerenv ]] && [[ ! -e /.dockerinit ]] && exit 0 

set -xe 

# Install git (the php image doesn't have it) which is required by composer 
apt-get update -yqq 
apt-get install git -yqq 
apt-get install wget -yqq 
apt-get install zip unzip -yqq 

# Install composer 
curl -sS https://getcomposer.org/installer | php 
mv composer.phar /usr/local/bin/composer 

# Install phpunit, the tool that we will use for testing 
curl -o /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar 
chmod +x /usr/local/bin/phpunit 

# Install mysql driver 
# Here you can install any other extension that you need 
docker-php-ext-install pdo pdo_mysql mbstring 
相关问题