简体   繁体   English

我如何在mysql docker service上创建数据库

[英]how can i create a database on mysql docker service

I'm trying to run moodle phpunit on my gitlab ci server. 我正在尝试在gitlab ci服务器上运行moodle phpunit。 Using gitlab-ci.yml file i'm creating a container with php 5.6 and mysql service. 我使用gitlab-ci.yml文件使用php 5.6和mysql服务创建一个容器。

# Services
services:
  - mysql:latest

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

I'm getting ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) and not sure how to proceed. 我收到ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)并且不确定如何继续。

Tomasz this is my gitlab-ci.yml file you will need something like this: Tomasz这是我的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

And this is my docker_install.sh inside ci folder 这是我在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM