简体   繁体   English

如何对接微服务 php 应用程序?

[英]How to dockerize a microservice php application?

I have around 10 microservices built on Yii PHP on my development environment.我的开发环境中有大约 10 个基于 Yii PHP 的微服务。 They are all running on vagrant.它们都在 vagrant 上运行。 They share the same database (MongoDB), and same Nginx.它们共享相同的数据库 (MongoDB) 和相同的 Nginx。 Some services uses elastic,redis,rabitmq....etc.一些服务使用elastic,redis,rabitmq....等。 I need to use docker instead of vagrant.我需要使用 docker 而不是 vagrant。 What is the best way to dockerize the whole application?将整个应用程序 docker 化的最佳方式是什么?

There is a lot of things if you are moving to dockerize your application.如果您要对应用程序进行 docker 化,有很多事情要做。 I have mention few tips that will help you in the development and production environment.我已经提到了一些可以在开发和生产环境中帮助您的技巧。

  1. You have to make Dockerfile for all the binaries (Elastic-Search, MongoDB, Redis, etc) and micro-services.您必须为所有二进制文件(Elastic-Search、MongoDB、Redis 等)和微服务制作 Dockerfile。 In Dockerfile you need to add only the required packages.在 Dockerfile 中,您只需添加所需的包。 Docker has a layered architecture. Docker 具有分层架构。 If anything changed in the previous layer it will affect the next all layer.如果上一层发生任何变化,它将影响下一层。 So, frequently changeable layers should be written at the end of Dockerfile.因此,频繁变化的层应该写在 Dockerfile 的末尾。 It will help a lot in the production environment.在生产环境中会有很大帮助。
  2. Make docker-compose.yml to run these binaries and services.制作 docker-compose.yml 来运行这些二进制文件和服务。 Dockerfile are used to make images but docker-compose.yml run that image. Dockerfile 用于制作图像,但 docker-compose.yml 运行该图像。 so, all the information required to run a service like networks, volume, commands, etc should be in docker-compose.yml因此,运行网络、音量、命令等服务所需的所有信息都应该在 docker-compose.yml 中
  3. You can use Jenkins for the CI/CD pipeline as well.您也可以将 Jenkins 用于 CI/CD 管道。
  4. Container orchestration tools like Kubernetes, docker swarm, etc, can be used for the production environment. Kubernetes、docker swarm 等容器编排工具可用于生产环境。

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

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