简体   繁体   English

Docker Compose(LAMP堆栈)的最佳部署策略

[英]Best deployment strategy with docker compose (LAMP stack)

I decided to start using docker in all my projects, and I'm interested in best practices, when it comes to deployment. 我决定在我的所有项目中开始使用docker,并且对部署方面的最佳实践感兴趣。

If I have a local docker environment, that is running a php-apache, mysql, and redis service, what's the best strategy when deploying? 如果我有一个本地docker环境,正在运行php-apache,mysql和redis服务,那么部署时的最佳策略是什么? Do you have a custom docker-compose config for production, which removes the redis and mysql services (assuming you'd want those on their own dedicated server)? 您是否有用于生产的自定义docker-compose配置,该配置会删除redis和mysql服务(假设您希望将它们放在自己的专用服务器上)?

There are a number of viable ways to run PHP containers in production, so it's a little hard to answer your question comprehensively. 有许多可行的方法可以在生产环境中运行PHP容器,因此很难全面回答您的问题。 I'll offer a few options: 我将提供一些选择:

  • Use a container hosting service like Docker Cloud to host your PHP code with the built-in Apache service. 使用诸如Docker Cloud之类的容器托管服务,通过内置的Apache服务托管您的PHP代码。
  • Use an orchestration service (like Swarm or Kubernetes ) hosted on your own servers. 使用托管在您自己的服务器上的编排服务(例如SwarmKubernetes )。 You'll have more setup here, but it will also give you more control. 您将在此处进行更多设置,但同时也会获得更多控制权。 There are also services that make this easier like Rancher or Codemason . 也有RancherCodemason这样的服务使之更容易。
  • Run docker-compose on one machine. 在一台机器上运行docker-compose。 Sure, it's not horizontally scalable, but if you're just working on a side project or small app, you can run all your containers on one server to start. 当然,它不是水平可伸缩的,但是如果您只是在开发一个副项目或小型应用程序,则可以在一台服务器上运行所有容器以启动。

As a note on database containers, you can containerize your database, and assuming that you put the actual data in a volume and have a sensible backup system in place there's no reason that containers won't be safe. 作为数据库容器的注释,您可以对数据库进行容器化,并假设将实际数据放入一个卷中并具有适当的备份系统,则没有理由说容器不安全。 You probably want to start by running just one container for your database or by using a hosted database service as scaling a database across multiple containers can get complicated (but here's a little bit about how you might do it with MySQL ). 您可能想从只为数据库运行一个容器或通过使用托管数据库服务开始,因为跨多个容器扩展数据库可能会变得很复杂(但是这里介绍了如何使用MySQL进行操作 )。

I guess I'll be answering this myself. 我想我会自己回答。

After some more intensive digging, I found out that it's not a very good idea to deploy the database within a container. 经过更深入的挖掘后,我发现在容器内部署数据库不是一个好主意。 If I use swarm, it would be very difficult to maintain data integrity across the whole system. 如果使用群集,则很难在整个系统中维护数据完整性。

Looks like most people just host the database separately, and only containerize the db in local development environments. 看起来大多数人只是单独托管数据库,并且只在本地开发环境中对数据库进行容器化。

So for deployment, best option right now is to deploy just the configured web server and any other stateless server requirements. 因此,对于部署,目前最好的选择是仅部署已配置的Web服务器以及任何其他无状态服务器需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM