我正在尝试使用我的主机(OSX Sierra)上的 Phinx 运行迁移,但我不断收到 PDO 连接错误。这是一个简单的 LAMP 堆栈,否则工作正常。
这是我的码头工人撰写:
version: '2'
services:
apache:
build:
context: ./docker/apache-php7
dockerfile: Dockerfile
volumes:
- ./app:/var/www
ports:
- "80:80"
- "443:443"
networks:
- localnet
links:
- mysql
mysql:
image: mysql:5.7
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "root"
MYSQL_USER: "root"
MYSQL_PASSWORD: "root"
volumes:
- ./db/mysql:/var/lib/mysql
networks:
- localnet
networks:
localnet:
driver: "bridge"
volumes:
mysqldata:
driver: "local"
redisdata:
driver: "local"
我的文件夹结构如下:
/app
/db/mysql
/docker
docker-compose.yml
我的 phinx.yml:
paths:
migrations: %%PHINX_CONFIG_DIR%%
seeds: %%PHINX_CONFIG_DIR%%
environments:
default_migration_table: phinxlog
default_database: docker
production:
adapter: mysql
host: localhost
name: %%PHINX_DBNAME%%
user: %%PHINX_DBUSER%%
pass: %%PHINX_DBPASS%%
port: 3306
charset: utf8
development:
adapter: mysql
host: localhost
name: %%PHINX_DBNAME%%
user: %%PHINX_DBUSER%%
pass: %%PHINX_DBPASS%%
port: 3306
charset: utf8
docker:
adapter: mysql
host: mysql
name: foo_db
user: root
pass: root
port: 3306
charset: utf8
这是我从主机运行命令(php ~/projects/project/app/vendor/bin/phinx migrate)时得到的输出。
using config file ./phinx.yml
using config parser yaml
using migration paths
- /Users/foo/projects/project/app/migrations
using seed paths
- /Users/foo/projects/project/app/migrations
warning no environment specified, defaulting to: docker
using adapter mysql
using database foo_db
[InvalidArgumentException]
There was a problem connecting to the database: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
我尝试重建图像,尝试了其他图像,但似乎不起作用。我可以使用具有以下配置的 SequelPro 从我的主机连接到 Docker MySQL:
Host: 0.0.0.0
Username: root
Password: root
Databse:
Port: 3306
我需要做什么/修复才能从我的主机在 MySQL 容器上运行这些 Phinx 迁移,因为替代方法是使用另一个我试图避免的Docker 容器?