У меня проблемы с пакетом Doctrine Migration в Symfony 4. Я запускаю свое веб-приложение в контейнерах Docker. При попытке выполнить миграцию после запуска контейнеров происходит сбой миграции с исключением «отказано в соединении». Но:
- Когда я пытаюсь подключиться к MySQL в своем собственном контейнере с хоста или в контейнере FPM, все работает нормально
- При выполнении команды, использующей Doctrine, все работает нормально.
Пример:
root@3af0cf70b099:/var/www# php bin/console doctrine:migration:migrate -qn
In StreamSocketClient.php line 225:
Failed to write to socket: fwrite(): send of 185 bytes failed with errno=111 Connection refused (8)
doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--db DB] [--em EM] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> [<version>]
root@3af0cf70b099:/var/www# php bin/console dbtest
[OK] Found user with login demo
root@3af0cf70b099:/var/www# php bin/console doctrine:migration:migrate -qn
In StreamSocketClient.php line 225:
Failed to write to socket: fwrite(): send of 185 bytes failed with errno=111 Connection refused (8)
doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--db DB] [--em EM] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> [<version>]
root@3af0cf70b099:/var/www#
Миграция работает только через 20 секунд после запуска контейнера.
Конфигурация моей доктрины:
doctrine:
dbal:
# configure these for your database server
driver: '%env(DB_DRIVER)%'
server_version: '%env(DB_SERVER_VERSION)%'
charset: '%env(DB_CHARSET)%'
default_table_options:
charset: '%env(DB_CHARSET)%'
collate: '%env(DB_COLLATION)%'
mapping_types:
enum: string
types:
phone_number: Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType
url: 'mysql://%env(DB_USER)%:%env(MYSQL_ROOT_PASSWORD)%@%env(DB_HOST)%:%env(DB_PORT)%/%env(MYSQL_DATABASE)%'
orm:
auto_generate_proxy_classes: false
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
Конфигурация миграции доктрин по умолчанию:
doctrine_migrations:
dir_name: '%kernel.project_dir%/src/Migrations'
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
namespace: DoctrineMigrations