4

I'm trying to run console run Doctrine 2's console script through the PhpStorm. Docker is set up as Deploy server.

If I run this:

$ docker exec container_name /var/www/vendor/bin/doctrine-module orm:schema-tool:create

it prints:

No Metadata Classes to process.

But when I run PHP Run/Debug configuration in PhpStorm: File: /home/username/PhpstormProjects/proj/vendor/bin/doctrine-module

it prints:

docker://image_name/container_name /var/www/vendor/bin/doctrine-module

Fatal error: Uncaught PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/vendor/zendframework/zend-servicemanager/src/ServiceManager.php on line 765

Zend\ServiceManager\Exception\ServiceNotCreatedException: Service with name "doctrine.connection.orm_default" could not be created. Reason: An exception occured in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/vendor/zendframework/zend-servicemanager/src/ServiceManager.php on line 765

Call Stack: 0.0001 349368 1. {main}() /var/www/vendor/doctrine/doctrine-module/bin/doctrine-module:0 0.0268 360480 2. include('/var/www/vendor/doctrine/doctrine-module/bin/doctrine-module.php') /var/www/vendor/doctrine/doctrine-module/bin/doctrine-module:4 0.9376 4076096 3. Zend\ServiceManager\ServiceManager->get() /var/www/vendor/doctrine/doctrine-module/bin/doctrine-module.php:61 0.9376 4076096 4. Zend\ServiceManager\ServiceManager->doCreate() /var/www/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:200

Process finished with exit code 255

I checked that when PDO is creating it receives absolutely the same arguments

new PDO("mysql:host=db;port=3306;dbname=dbname", "user", "pass", [])

docker-compose.yml:

version: '2'
services:
    nginx:
        container_name: nginx
        build:
            context: .
            dockerfile: DockerfileNginx
        ports:
            - "80:80"
        depends_on:
            - php
        working_dir: /var/www
        links:
            - php
        volumes:
            - .:/var/www
        links:
            - db
    php:
        container_name: php
        build:
            context: .
            dockerfile: DockerfilePhp
            - db
        volumes:
            - .:/var/www
        expose:
            - "9000"
        depends_on:
            - db
    db:
        container_name: db
        image: "mysql:5.6"
        ports:
            - "3306:3306"
        environment:
            MYSQL_ROOT_PASSWORD: pass
            MYSQL_DATABASE: dbname
            MYSQL_USER: user
            MYSQL_PASSWORD: pass
2
  • I guess you should use localhost instead of db in the connection string, because PHPStorm is running from outside containers: new PDO("mysql:host=localhost;port=3306;dbname=dbname", "user", "pass", []); That should work as you already mapped "3306:3306" (there's a strange character after that btw) Commented Jan 18, 2017 at 21:22
  • PHPStorm executes the tests inside the container. The host "db" is correct. Commented Jan 31, 2017 at 13:08

1 Answer 1

11

I had the same problem and I found out, that PHPStorm starts a new, dedicated Docker container for your PHP calls. So, all your docker-compose configuration is missing at this point.

I did the following:

  • start your Docker stack with compose
  • after that find your network name with docker network ls (see Cannot link to a running container started by docker-compose for help)
  • inside PHPStorm goto your preferences for your Docker container (Languages & Frameworks -> PHP -> PHPUnit: Docker container ...) and add a link to your db (something like: name = your_containter_name_1, alias = db) and change the network mode from bridge to your network name
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.