如何为旨在在3个不同主机中运行的现有Docker Compose文件设置Docker Swarm? [英] How to setup Docker Swarm for an existing Docker Compose file intended to run in 3 different hosts?

查看:234
本文介绍了如何为旨在在3个不同主机中运行的现有Docker Compose文件设置Docker Swarm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力寻找解决我的(也许很简单)问题的最佳解决方案.

我有一个(一个)docker撰写文件,其中包含一些服务:

  • Rest-Api(java)
  • 蒙哥
  • Redis

其余api需要可扩展. Java-1,Java-2,Java-3等.

您在下面看到的是3位不同的主机.当我所有的主机都启动时,对所有脚本进行脚本编写的最佳解决方案是什么?我希望能够执行docker-compose up -d之类的操作,并在3个不同的主机上生成我的服务.

我知道docker swarm可以做些什么.我还阅读了有关与Swarm结合使用的Weave网络的信息.老实说,我很难把所有东西都放在一起.了解如何使其基本工作...

(当然)要对Java主机进行负载平衡.

我的主机1会成为我的群管理员吗?接待2名工人和3名工人?我该如何处理?

您有什么建议吗? Rancher,Portainer,Docker-Machine,其他...?

     Host 2
+-------------+                               
|             |                               
|   Java 1    |               Host 1       
|             |---\      +-------------------+
+-------------+    ---\  |                   |
                       --|   Mongo, Redis    |
    Host 3             --|                   |
+-------------+     --/  +-------------------+
|             |  --/                          
|   Java 2    |-/                             
|             |                               
+-------------+                               

    Host #
    ...

我的RestApi服务和数据库之间的链接需要加密.

解决方案

您已经提到Docker Swarm可用于解决您的问题.最初,您应该了解的是Java(API),不应将Mongo和Redis标识为主机.在群集模式下,它们将是 docker服务 .因此,在您的情况下,您的Docker集群中将提供三项服务.在主机上扩展它是使用Docker Swarm完成的一项工作.正如您已经提到过的那样,您应该对Java(API)进行扩展,从一个起点开始,假设您将从3个Java(API)服务开始,因此,假设您在Docker Swarm中有三台主机,一个是管理器,另外两个是worker(确定哪个主机成为管理者取决于您,这取决于您),您只需要创建Java(API)服务的三个副本即可,即使一个主机发生故障,Docker Swarm也会自动在这三个主机上运行这三个副本,即使Docker Swarm会自动运行将流量重定向到正在运行容器的主机,并且将始终运行您已告诉其运行的副本的数量.这意味着如果一个容器失败,它将被重新创建.这些服务可以根据您的目的通过简单的命令轻松扩展.因此,一个好的出发点是阅读有关 Docker Swarm Official文档本身.然后按照官方群教程.

在Docker集群模式下,有一个称为堆栈的功能,通过堆栈,您可以简单地将完整的应用程序堆栈部署到集群.您可以从此处进行阅读. .就您而言,如前所述,您已经拥有了compose文件,可用于部署堆栈.您将需要更新现有的撰写文件,以与您的应用程序堆栈中需要的配置相匹配.只需在docker-compose.yml文件中提及您想要什么以及如何想要它,Docker Swarm就会为您创建它.

在您了解了这些概念并准备好Docker Swarm设置以及具有所有Workers和Managers设置的主机之后,请遵循以下令人敬畏的覆盖类型的网络专门将Docker集成到您的应用程序中.这将允许在多个Docker守护程序主机(节点)之间建立分布式网络.

编辑-默认情况下,使用 GCM 模式.创建覆盖网络时,也可以通过添加--opt encrypted来加密应用程序数据.如文档所述,这将带来不可忽略的性能损失,因此在生产中运行该功能之前应进行测试. 引用 6 加密覆盖网络部分的流量.

希望此说明将帮助您了解Docker Swarm如何解决您的问题并阐明您面临的问题.

I'm trying to figure out the best solution for my (maybe simple) problem.

I have a (one) docker compose file with some services :

  • Rest-Api (java)
  • Mongo
  • Redis

The rest api needs to be scalable. Java-1, Java-2, Java-3, etc.

What you see below are 3 different hosts. What's the best solution to script everything when all my hosts are up? I want to be able to do something like docker-compose up -d and spawn my services on 3 differents hosts.

I know docker swarm can do something. I've also read about Weave network with combination with Swarm. Honestly, I'm having a hard time to put everything toghether; understanding how to make it work basically...

The Java Hosts are to be load balanced (of course).

Will my Host 1 be my swarm manager? Host 2 and 3 workers? How can I manage this.?

Do you have any recommendations? Rancher, Portainer, Docker-Machine, other...?

     Host 2
+-------------+                               
|             |                               
|   Java 1    |               Host 1       
|             |---\      +-------------------+
+-------------+    ---\  |                   |
                       --|   Mongo, Redis    |
    Host 3             --|                   |
+-------------+     --/  +-------------------+
|             |  --/                          
|   Java 2    |-/                             
|             |                               
+-------------+                               

    Host #
    ...

EDIT : links between my RestApi services and the database need to be encrypted.

解决方案

As you have mentioned Docker Swarm can be used to solve your problem. Initially what you should understand is your Java (API), Mongo and Redis should not be identified as hosts. They would be docker services in the swarm mode. So in your case, you would have three services in your docker swarm. Scaling it on your hosts is a job that's being done with Docker Swarm. As you have mentioned your Java (API) should be scaled, as a starting point imagine you would start with 3 Java (API) services, so imagine you have three host machines in your Docker Swarm, one is a manager other two are workers (deciding which host becomes manager which hosts are workers is up to you) and you just need to create three replicas of Java (API) services and Docker Swarm will run those three replicas on those three hosts, even if one host fails Docker Swarm will automatically redirect the traffic to hosts which are running the containers and will always run the number of replicas that you have told it to run. Which means if a container fails it will be recreated. These services can be easily scaled with simple command based on your purpose. So a good starting point would be to read about Docker Swarm Official documentation itself. Then follow the official swarm tutorial.

In Docker swarm mode, there is a feature called a stack, a stack would enable you to simply deploy a complete application stack to the swarm. You can read about it from here. In your case, as you have mentioned you already have the compose file with you, which can be used to deploy a stack. You would need to update your existing compose file to match with the configurations you need to have in your application stack. It's just a matter of mentioning what do you want and how you want it in the docker-compose.yml file and Docker Swarm would create it for you.

After you have read about those concepts and ready with Docker Swarm setup and hosts with all the Workers and Managers set-up follow this awesome Docker Swarm vote app example. Read the Docker Stack file of that example which will allow you to understand how to properly define your application stack which will provide you a solid understanding about Docker Stacks and use the same example file as a base for designing your application stack.

After that, it's a matter of deploying your stack. Simply by running docker stack deploy -c docker-compose.yml yourAppName.

Adding another point into all this is you can create a separate overlay type network in Docker specifically into your app. This would allow a distributed network among multiple Docker daemon hosts (nodes).

Edit - All swarm service management traffic is encrypted by default, using the AES algorithm in GCM mode. You can encrypt application data as well by add --opt encrypted when creating the overlay network. As the documentation mentions, this will carry a non-negligible performance penalty, so testing is expected before running the feature in production. Refer 6 Encrypt traffic on an overlay network section.

Hope this explanation would help you understand how Docker Swarm would solve your problem and clarify the issues you are facing.

这篇关于如何为旨在在3个不同主机中运行的现有Docker Compose文件设置Docker Swarm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆