phpunit不与docker中的mysql连接

时间:2018-09-03 13:36:58

标签: docker docker-compose phpunit

Symfony连接数据库(和php容器),但是当我运行phpunit时返回错误SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known。我的项目在哪里出错?

在我的项目docker-compose.yml文件中,该文件看起来像:

services:
    db:
        image: mysql:5.7
        environment:
            MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
            MYSQL_DATABASE: ${MYSQL_DATABASE}
            MYSQL_USER: ${MYSQL_USER}
            MYSQL_PASSWORD: ${MYSQL_PASSWORD}
        ports:
            - 8989:3306
    php:
        build:
            context: docker/php7-fpm
            args:
                TIMEZONE: ${TIMEZONE}
        volumes:
            - ${SYMFONY_APP_PATH}:/var/www/symfony
            - ./logs/symfony:/var/www/symfony/app/logs
        depends_on:
          - db
        links:
          - db:db

1 个答案:

答案 0 :(得分:0)

environment服务的db配置和args服务的php设置应以-字符开头。