How to implement microservices architecture with docker compose?

﹥>﹥吖頭↗ 提交于 2020-01-05 21:11:12

问题


I am working on a web application that requires few microservices like a URL shorter, mailer, analytics, etc... Each of these services are implemented as REST api so they can talk to each other. Each of these services have a docker-compose.yml file and use containers like nginx, php, mysql, etc… I want these to work as a single system. I don’t want to expose these REST apis to anyone outside of the docker network

My question is how can I combine multiple docker-compose.yml files from each service so they work together? Or should I use one big docker-compose.yml file to define all the services under one network? Or should I base each of my service only on one container (ubuntu as base and install php, mysql, nginx through Dockerfile) then run them through docker-compose.yml, on a shared network? Or have I misunderstood implementing microservices with Docker?


回答1:


how can I combine multiple docker-compose.yml files from each service so they work together?

If you choose this path, make sure that your containers attach to the same network. You can find information about this case here: Networking in Compose: Use a pre-existing network.

Or should I use one big docker-compose.yml file to define all the services under one network?

It is again up to you to decide if this should be your approach. In this case, you are correct, all the containers can attach to the default network that is going to be created. From the same docs:

Note: Your app’s network is given a name based on the “project name”, which is based on the name of the directory it lives in. You can override the project name with either the --project-name flag or the COMPOSE_PROJECT_NAME environment variable.

Or should I base each of my service only on one container (ubuntu as base and install php, mysql, nginx through Dockerfile)

I am not quite sure, what you mean here exactly...

  • if you talk about having all these installed to one container, don't do it. This way you get back to a "monolith" approach.
  • if you talk about starting with "ubuntu" as a base and continue by building separate containers for php, mysql, nginx etc, you can do it. But I would suggest you to better use the official images provided by https://hub.docker.com


来源:https://stackoverflow.com/questions/48663545/how-to-implement-microservices-architecture-with-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!