简体   繁体   English

微服务和数据库:mongodb docker-如何设置容器

[英]micro-services and database : mongodb docker - how to set up containers

I'm creating an app using micro-services architecture, using mongodb, nodejs, and docker. 我正在使用mongodb,nodejs和docker使用微服务架构创建应用程序。

I read that, each micro-services should have his own database, and I guess each microservice live in a separate container. 我读到,每个微服务都应该有自己的数据库,而且我猜每个微服务都位于单独的容器中。 So I guess 1 micro-service = 1 container 所以我想1个微服务= 1个容器

But what about their respecting databases, should they also live in the same micro-service container ? 但是,他们尊敬的数据库又该如何生活在同一个微服务容器中呢? So it would be 1 micro-service = 1 container (with 1mongo image + 1nodejs image) 因此它将是1个微服务= 1个容器(带有1mongo映像+ 1nodejs映像)

Or is it more like 1micro-service = 1container(app) + 1container(database) 还是更像1micro-service = 1container(app)+ 1container(database)

I'm trying to implement this way right now, but each time I down my container, the volume is removed... 我现在正在尝试以这种方式实现,但是每次我放下容器时,都会删除该卷...

So i'm wondering, how should I set up my database and containers to properly apply a micro-service architecture 所以我想知道如何设置数据库和容器以正确应用微服务架构

Thanks in advance for any feedback 预先感谢您的任何反馈

You should run one service in at least one container. 您应该在至少一个容器中运行一项服务。 In the situation you're describing, for basically exactly the reasons you describe, it's generally important to run your databases in separate containers (you don't want to have to destroy and restart your database just because you updated application code). 在您正在描述的情况下,基本上完全出于您描述的原因,在单独的容器中运行数据库通常很重要(您不必仅因为更新了应用程序代码而销毁并重新启动数据库)。

(Imagine you were running things purely locally: the situation is analogous to your application starting and stopping the database on its own. It's administratively a little easier at first glance, but if the application vs. database is having trouble, or if you need to scale things, or ..., you'd be much happier directly managing the database.) (想象一下,您纯粹是在本地运行的事情:这种情况类似于您的应用程序自行启动和停止数据库。乍看之下在管理上要容易一些,但是如果应用程序与数据库之间有麻烦,或者您是否需要扩展规模,或者……,直接管理数据库会更加愉快。)

This Kubernetes question has a good higher-level picture: in that question there are a half-dozen services, plus one of them has a backing database, and these are each running in separate containers (in that question separate Kubernetes Deployments/StatefulSets/Pods). 这个Kubernetes问题具有较高的整体印象:该问题中有六个服务,其中一个具有备份数据库,并且每个服务都在单独的容器中运行(在这个问题中,单独的Kubernetes Deployments / StatefulSets / Pods )。 Logically "service B plus its backing database" might be a single unit but you'd deploy the two halves in separate containers. 从逻辑上讲,“服务B及其后备数据库”可能是一个单元,但是您需要将这两个部分部署在单独的容器中。

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

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