I am yet to find an elegant and efficient way to run Laravel Artisan commands in my Docker based local dev environment.

有没有人能推荐一种推荐的或"适当的"方式来做像迁移这样的事情?

或者,有人找到了一种巧妙的方法吗?最好是有例子或建议.

我考虑过的事情:

  • 一个新的容器(共享相同的卷和数据库链接)与ssh一起使用,仅用于运行命令(看起来很糟糕).
  • Hacks in supervisor that could then end up running on live (not ideal).
  • Editing db configs, or trying to hack in a "host" environment, so that at least things like migrate can be run from the host.
  • Creating web front ends to run things (really nasty).
  • 试图为it事物建立一个"信号".

I'm still getting my head around Docker and it's new-container-for-everything approach.

I suppose I want to balance cool-dev-ops stuff with why-do-I-need-another-fake-server-just-get-it-working-already.

我很愿意在我的开发工作流程中使用它,但在某些情况下使用它似乎会变得很尴尬,就像这样……

Any suggestions and ideas are welcome. Thanks all.

推荐答案

关于Docker的最佳实践是在自己的容器中运行每个进程.因此,运行artisan个命令的理想方式是创建一个专门用于此目的的容器的图像.

I've created an image which can be pulled from the Docker Hub dylanlindgren/docker-laravel-artisan and it works really well. It's on GitHub as well if you want to take a look at the Dockerfile behind it.

I've also just written a blog post describing the way that all these seperate containers fit together.

Laravel相关问答推荐

1 子编译中的警告(使用'stats.children:true'和'--stats-children'了解更多详细信息)

不能在 laravel 中使用控制器名称,必须使用命名空间

如何访问 Validator::extend 中的其他输入属性?

Laravel 5.3 创建模型返回字段没有默认值

Laravel Session 总是改变 Laravel 5.4 中的每个刷新/请求

如何使用 Laravel 模型访问数据库视图?

会话中的 Laravel 存储数组

如何使用 ajax 请求删除 laravel 5.3 中的记录?

为什么人们将 .env 放入 gitignore?

Laravel 4 定义 RESTful 控制器

有条件的Eager加载

Laravel 5.1 重命名项目

使用模型工厂、一对一和一对多关系定义 Laravel 外键,而不创建不必要的模型

Web 服务器如何处理请求?

Laravel 应用程序连接数据库时速度很慢

如何在 laravel 用户删除中重置自动增量?

Mac OS X 需要 Mcrypt PHP 扩展

Laravel - 使用 Eloquent 查询构建器在 Select 中添加自定义列

phpunit 命令不适用于 Windows 7 上的 laravel 4

限制自己重载外部 API 的速率