Skip to content

Symfony requires a git repository to run docker commands #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexandresalome opened this issue Dec 16, 2024 · 5 comments · Fixed by #555
Closed

Symfony requires a git repository to run docker commands #550

alexandresalome opened this issue Dec 16, 2024 · 5 comments · Fixed by #555

Comments

@alexandresalome
Copy link

alexandresalome commented Dec 16, 2024

When I run symfony console, Symfony CLI does not detect my docker compose containers. The error happens when there is no .git directory in the Symfony project directory.

  • Ubuntu 22.04 LTS
  • Docker 27.3.1
  • Symfony CLI version 5.10.5

How to reproduce

mkdir sf-git-producer
cd sf-git-producer
git init .
symfony new --no-git --webapp inner
cd inner
docker compose up -d
symfony console doc:query:sql 'SHOW TABLES'

This command returns an error because there is no git directory.

Actual output

  SQLSTATE[08006] [7] connection to server at "127.0.0.1", port 5432 failed: Connection refused
  	Is the server running on that host and accepting TCP/IP connections?

Expected result

I would expect it to try connecting to a different server & port, according to DATABASE_URL.

When I run symfony serve, the profiler toolbar indicates no database/mailpit. symfony run env shows no special environment variable for the database.

Workaround

I workaround by running git init before any symfony command:

# run this before your command to fix the problem
git init .

symfony console doc:query:sql 'SHOW TABLES'

# delete to break future execution
rm -rf .git

Final note

Don't forget to cleanup:

docker compose down
@tucksaun
Copy link
Member

#546 might be the occasion (or lay the ground) to fix this. wdyt?

@jankal
Copy link

jankal commented Dec 18, 2024

symfony-cli recently (f11e67e) switched to guessing the project directory based on the presence of a .git directory. I think this change did not consider a lot of use cases besides the standard single git-tracked symfony project.

I recently created #551 to determine the project directory based on the presence of .symfony.local.yaml - we could think about taking (?:docker-)?compose\.ya?ml into account as well. Would any of these changes fix your issue?

@alexandresalome
Copy link
Author

@jankal this file is not present in my project, neither in the project that I create using the reproducer above. So #551 would not address my issue. What about symfony.lock or composer.json?

@jankal
Copy link

jankal commented Dec 19, 2024

@alexandresalome I guess symfony.lock would fit best.

I am against composer.json as one could have their PWD in some vendor code which also contains a composer.json thus leading to the projectDir being detected in some library folder.

I will update my PR code in #551 accordingly.

@alexandresalome
Copy link
Author

I confirm that the problem was fixed in 5.10.6, the reproducer does not reproduce anymore and my project is also fixed!

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants