如何在docker中运行phinx?

ubby3x7f  于 2023-06-22  发布在  Docker
关注(0)|答案(2)|浏览(127)

我有一个docker配置(php,mysql,nginx),我需要运行phinx
问题是,当我运行vendor/bin/phinx migrate -e development命令时,系统无法在Docker容器上工作,即使我将phinx.yml配置为这样!
我有这个错误消息:

PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/.
/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:80
Stack trace:
#0 /var/www/html/     /vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php(80): PDO->__construct()

这意味着phinx无法识别docker配置。

phinx.yml:

paths:
    migrations: '%%PHINX_CONFIG_DIR%%/db/migrations'
    seeds: '%%PHINX_CONFIG_DIR%%/db/seeds'

environments:
    default_migration_table: phinxlog
    default_environment: development
    production:
        adapter: mysql
        host: service_mysql
        name: mydb
        user: root
        pass: '123456'
        port: 3306
        charset: utf8

    development:
        adapter: mysql
        host: service_mysql
        name: my_database
        user: root
        pass: '123456'
        port: 3306
        charset: utf8

    testing:
        adapter: mysql
        host: localhost
        name: testing_db
        user: root
        pass: ''
        port: 3306
        charset: utf8

version_order: creation

我的问题是如何在docker中使用phinx?

z31licg0

z31licg01#

我找到了答案,我应该在docker php容器中运行phinx命令:

sudo docker exec docker_myphp_fpm_1 vendor/bin/phinx migrate -e development
tquggr8v

tquggr8v2#

你的docker容器很可能不在同一个网络中。

相关问题