我正在尝试通过PhpStorm运行控制台运行的Doctrine 2的控制台脚本。 Docker设置为Deploy server。
如果我这样做:
$ docker exec container_name /var/www/vendor/bin/doctrine-module orm:schema-tool:create
打印:
没有要处理的元数据类。
但是当我在PhpStorm中运行PHP运行/调试配置时: 文件:/ home / username / PhpstormProjects / proj / vendor / bin / doctrine-module
打印:
docker:// image_name / container_name / var / www / vendor / bin / doctrine-module
致命错误:未捕获PDOException:PDO :: __ construct():php_network_getaddresses:getaddrinfo failed:第765行/var/www/vendor/zendframework/zend-servicemanager/src/ServiceManager.php中未知的名称或服务
Zend \ ServiceManager \ Exception \ ServiceNotCreatedException:无法创建名为“doctrine.connection.orm_default”的服务。原因:驱动程序中发生异常:SQLSTATE [HY000] [2002] php_network_getaddresses:getaddrinfo failed:第765行/var/www/vendor/zendframework/zend-servicemanager/src/ServiceManager.php中未知的名称或服务
调用堆栈: 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
处理完成,退出代码为255
我检查过PDO正在创建它时会收到完全相同的参数
new PDO("mysql:host=db;port=3306;dbname=dbname", "user", "pass", [])
搬运工-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
答案 0 :(得分:10)
我遇到了同样的问题,我发现,PHPStorm为您的PHP调用启动了一个新的专用Docker容器。因此,此时缺少所有的docker-compose配置。
我做了以下事情:
docker network ls
找到您的网络名称(请参阅Cannot link to a running container started by docker-compose寻求帮助)