我有 php5.6-apache image build on ubuntu 和 mysql:5.6 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)
最佳答案
您没有正确配置数据库。通过您的配置,mysql 在主机 mysql
和端口 3306
上可用。相反,您的应用程序正在尝试通过 unix 套接字进行本地连接。配置连接,一切正常。
关于php - 使用 php 和 mysql 创建 docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41442340/