[英]Should you create separate docker containers for services like redis and elastic search when they are being used by more than one other service?
I have my entire stack in a docker compose container setup. 我将整个堆栈放在docker compose容器设置中。 Currently, load is such that it can all run on a single instance.
当前,负载可以全部在单个实例上运行。 I have two separate applications and they both use redis and elastic search.
我有两个单独的应用程序,它们都使用Redis和弹性搜索。
I have seen people suggesting that in cases like MySQL, proper container theory suggests that you should have two separate containers for two separate databases, if you have two separate applications using them. 我见过有人建议,在类似MySQL的情况下,正确的容器理论建议,如果您有两个使用它们的独立应用程序,则应该为两个独立的数据库拥有两个独立的容器。
Which I think is fine for MySQL because my understanding is that separate instances of MySQL doesnt really add much memory or processor overhead. 我认为这对MySQL很好,因为我的理解是,单独的MySQL实例实际上并不会增加太多的内存或处理器开销。
I'm wondering if this same strategy should apply to redis and elasticsearch. 我想知道是否应该将相同的策略应用于redis和elasticsearch。 My understanding is that both of these applications can come with considerable overhead.
我的理解是,这两个应用程序都可能带来相当大的开销。 So it seems like it might be inefficient to run more than one instance of them.
因此,似乎无法运行多个实例。
It's an interesting question, but I'm not sure there is an universal answer to this. 这是一个有趣的问题,但是我不确定对此是否有一个普遍的答案。 It mostly depends on your situation.
这主要取决于您的情况。
However, there are advantages and drawbacks you must know if you are using a unique container for multiple applications. 但是,如果您将唯一的容器用于多个应用程序,则必须了解其优缺点。 As an example, let's say you have only 2 applications containers : A and B , and a shared DB container, whatever the technology behind.
举个例子,假设您只有两个应用程序容器: A和B ,以及一个共享的DB容器,无论使用哪种技术。
If A and B are independent applications, then the main disadvantage by sharing DB is that you break that independency and tightly couple your applications via DB : 如果A和B是独立的应用程序,则共享DB的主要缺点是您将打破这种独立性,并通过DB紧密耦合您的应用程序:
If A and B are already tightly coupled apps, then you can probably go for 1 DB . 如果A和B已经是紧密耦合的应用程序,那么您可能可以选择1 DB 。 If you don't have many resources, you can also share DB .
如果您没有很多资源,也可以共享DB 。 But don't forget that by doing this, you couple your apps, which you probably doesn't want.
但是不要忘记这样做,您可以耦合应用程序,而这可能是您不想要的。 Otherwise, the cleanest solution is to go for 1 DB per application.
否则,最干净的解决方案是每个应用程序使用1个DB 。
The main benefit I see which comes from having all linked services in the docker compose stack is that docker will then ensure that all required services are up. 我看到的主要好处是,泊坞窗组成堆栈中具有所有链接的服务,然后泊坞窗将确保所有必需的服务正常运行。 However with services like redis and elastic it is fine to have them installed stand-alone with the application just pointing to them via environment variables passed in the docker compose file.
但是,使用redis和elastic之类的服务时,最好将它们与应用程序一起独立安装,仅通过泊坞窗组成文件中传递的环境变量指向它们。
eg 例如
myapp:
image: myawesomerepo/myapp:latest
depends_on:
- someother_svc_in_same_docker_compose
environment:
- DB_HOST=172.17.2.73
- REDIS_HOST=172.17.2.103
- APP_ENV=QA
- APM_ENABLE=false
- APM_URL=http://172.17.2.103:8200
- CC_HOST=cc-3102
volumes:
- /opt/deploy/cc/config:/server/app/config
- /opt/deploy/cc/slogs:/server/app/logs
command: node ./app/scheduler/app.js
In the future if you decide you want to have these services hosted, for example, you just need to point the URL in the right direction. 例如,将来如果您决定要托管这些服务,则只需将URL指向正确的方向即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.