我試圖從我的主機(OSX Sierra)中使用Phinx進行遷移,但我一直在收到PDO連接錯誤。這是一個簡單的LAMP堆棧,否則工作正常。在Docker容器上運行PHINX遷移時發生PDO連接錯誤
這裏是我的搬運工,撰寫:
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"
我的文件夾strucutre如下:
/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
我試過重建圖像,嘗試過其他圖像,但似乎沒有工作。
Host: 0.0.0.0
Username: root
Password: root
Databse:
Port: 3306
什麼我需要做的/修復,以便從我的主機作爲替代運行MySQL容器上按照Phinx遷移:我可以用SequelPro與下面的配置從我的主機連接泊塢窗的MySQL將使用另一個Docker Container,我試圖避免?
謝謝你的迴應。我對Docker很新,所以請原諒我的無知,但我嘗試從MySQL服務中刪除端口,並嘗試運行遷移,但仍然有相同的錯誤。我也嘗試從phinx.yml中刪除端口,並且仍然沒有運行遷移的工作。 –