symfony-docker
symfony-docker copied to clipboard
Autowire of repositories not working properly
Hello,
I'm trying to dockerize a Symfony 5.4
project that is currently working on, after follow the instructions here indicated: https://github.com/dunglas/symfony-docker/blob/main/docs/existing-project.md
and after build my dockerfile, I've get that my php container is rebooting randomly This is probably caused, for some problem regarding the autowired services.
The folder 'App\Repository' seems not be autowired, that cause the container exit with code 1 trying to make the cache:clear.
php_1 | Script cache:clear returned with error code 1
php_1 | !!
php_1 | !! In DefinitionErrorExceptionPass.php line 54:
php_1 | !!
php_1 | !! Cannot autowire service "App\Service\TokenToTransfer\TransferDetailsGenerat
php_1 | !! or": argument "$tokenToTransferRepository" of method "__construct()" refere
php_1 | !! nces class "App\Repository\TokenToTransferRepository" but no such service e
php_1 | !! xists.
php_1 | !!
php_1 | !!
php_1 | !!
php_1 | Script @auto-scripts was called via post-install-cmd
sto4all_dockerized_php_1 exited with code 1
(I've add manually that repository in the services.yaml making that error gone, but after that other services failed because other repositories failing to autowiring)
That folder should be autowired because the service.yaml config:
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
This project and configuration is working nicely with in local machine (w10) and in the prod server (centos) using php 8.0 with apache.
Moreover the other services of the project seems to be autowired perfectly, but I can't make this container work for this problem.
Any advice?
@Gonzalo1987 I was facing the same issues, and realized that some sub-folders of src/
were not readable by the php-fpm process.
Can you check that those folders have the right permissions?
Thanks for the support @thePanz , I've check the permissions of my container, and /app folder and subfolders (at least /app/src and /app/src/Repository) has 777 permissions for every file. It would be possible it wasn't readable by php-fpm, but when I put the repositories as independant services (without use the autowire although is enabled and works for the services in /Service folder) it works:
services.yaml
services:
App\Repository\XRepository:
App\Repository\YRepository:
App\Repository\ZRepository:
Seems related to: https://github.com/dunglas/symfony-docker/issues/166
Can you try to disable apcu and/or opcache in your develpment like explain here : https://github.com/dunglas/symfony-docker/issues/245
Sorry @maxhelias but still not autowiring the repository services :(
And this solution : https://github.com/dunglas/symfony-docker/issues/226#issuecomment-1106150198
I think it's related to filesystem/volumes sync between docker and the locale machine
Yes, you are right, if I remove the line: - ./:/srv/app:rw,cached
of my docker-compose.override.yaml it works.
Seems something related to the sync. A little annoying, it would be a docker desktop bug?
I don't know if it's docker or the filesystem provided for the OS but I often hear synchronization problems on windows. Personally I am on macOS and apart from the historical slowdowns which have been corrected on the last versions I never had this kind of problem.
Same issue here, any solution ?