CLI Not respecting .env file when using Docker

Đang mở
#430 5 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
docker-compose, go
Lĩnh vực
cli

Hướng nghiên cứu

Start by tracing how the Symfony CLI loads project .env values for symfony serve and symfony console, then compare behavior with Docker running and stopped using the reproduction steps and debug:container --env-vars. The issue reports conflicting environment values but names no source files or tests, so first locate the relevant environment-loading code and tests. Done means the project’s DATABASE_URL is used consistently while Docker is running.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I have local project that I'm setting up that uses docker for DB.
I've updated .env for DATABASE_URL env var to reflect what db url is but after serving that project with symfony serve errors appear Unknown database 'root'
After digging a bit in what's happening, it appears that symfony CLI is not using .env file from the project as it should, but it rather appears that it's using some other .env file when my docker is up.

Steps to reproduce:

  1. install default symfony app
  2. use docker for DB with provided yaml file
    docker-compose.yaml
version: '3.7'
services:
    database:
        image: 'mariadb'
        environment:
            MYSQL_ROOT_PASSWORD: password
        ports:
            - '3306:3306'
  1. start docker docker-compose up -d
  2. update your .env file to use DB that you want (in my case it's DATABASE_URL="mysql://root:[email protected]:3306/symfony?serverVersion=mariadb-11.2.2"
  3. run command to create DB php bin/console doctrine:schema:create and your db symfony should be created
  4. (optional) if you run symfony console doctrine:schema:create you'll see message that db root was created

Findings:
Now where does this error comes from as my db name is symfony and not root.
After checking symfony console debug:container --env-vars I've got this result:
DATABASE_URL "mysql://root:[email protected]:3306/root?sslmode=disable&charset=utf8mb4&serverVersion=1:11.2.2+maria~ubu2204" which means Symfony CLI didn't actually use my local .env file but rather something else.

Then it came to my mind to check what will happen if I stop docker DB, and re-run previous command. Response was different and I got what was actually in my defined DATABASE_URL: DATABASE_URL "mysql://root:[email protected]:3306/symfony?serverVersion=mariadb-11.2.2"

What should be expected behaviour?
Symfony CLI should use projects defined .env file

Symfony CLI Version:
Symfony CLI version 5.8.7 (c) 2021-2024 Fabien Potencier (2024-02-08T11:42:34Z - stable)

This issue could be related to #425 and #152

Ngôn ngữ chính
Go
Star
608
Fork
140
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của symfony-cli/symfony-cli

Tất cả issue của symfony-cli/symfony-cli

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.