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
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:
docker network ls
(see Cannot link to a running container started by docker-compose for help)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With