且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel在Docker容器中时无法连接到数据库

更新时间:2022-03-21 16:53:47

经过研究和思考,问题在于我不是从容器内部而是从外部运行迁移命令.

After some research and thinking about it, the problem was that I was not running the migrate command from within the container but from the outside.

这是我所做的:

  1. (在VS代码内)docker ps
  2. docker exec -it finance_app_backend_1 bash,结果:root@1bb6f2d30d8a:/var/www/html#
  3. cd finance_app/
  4. root @ 1bb6f2d30d8a:/var/www/html/finance_app#php artisan migration
  1. (Within VS Code) docker ps
  2. docker exec -it finance_app_backend_1 bash, result: root@1bb6f2d30d8a:/var/www/html#
  3. cd finance_app/
  4. root@1bb6f2d30d8a:/var/www/html/finance_app# php artisan migrate

它奏效了

Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (0.07 seconds)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (0.06 seconds)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (0.03 seconds)
Migrating: 2019_11_25_012607_create_cateagories_table
Migrated:  2019_11_25_012607_create_cateagories_table (0.04 seconds)
root@1bb6f2d30d8a:/var/www/html/finance_app#