简体   繁体   English

用php和mysql创建docker镜像

[英]Create docker image with php and mysql

I have php5.6-apache image built on ubuntu and mysql:5.6 image . 我有建立在ubuntu和mysql:5.6 image上的php5.6-apache 镜像 I want to create docker image from above two images so that I can use newly built image in gitlab ci . 我想从上面的两个映像创建docker映像,以便可以在gitlab ci中使用新建的映像。 How can I do that? 我怎样才能做到这一点? I am fairly new to docker and gitlab. 我是docker和gitlab的新手。

I tried following in gitlab, but didn't work. 我在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

I got following error when running composer install in gitlab ci. 在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)

You didn't configure the database properly. 您没有正确配置数据库。 With your configuration mysql is available on host mysql and port 3306 . 通过配置,可以在主机mysql和端口3306上使用mysql Instead your application is trying a local connection thru a unix socket. 相反,您的应用程序尝试通过unix套接字进行本地连接。 Configure the connection and all should work. 配置连接,所有都应该工作。

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

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