Docker-compose:在多个主机中部署服务 [英] Docker-compose: deploying service in multiple hosts

查看:1346
本文介绍了Docker-compose:在多个主机中部署服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个docker-compose文件,该文件在同一主机上部署8个不同的docker服务。是否可以在不同的主机中部署它?我想在一个主机中远程部署某些服务,而在其他主机中远程部署其他服务。我需要使用docker-swarm吗?还是更简单的方法?

I have a docker-compose file that deploys 8 different docker services in the same host. Is it possible to deploy it in different hosts?, I would like to deploy some service in one hosts and another ones in other host remotelly. Would I need to use docker-swarm? or is an easier way to do?

我已经阅读到可以使用DOCKER_HOST完成此操作,但是如果我使用此变量配置/ etc / default / docker,服务将在远程主机上运行,​​而我需要的是一台远程主机中的某些服务,以及另一台远程主机中的其他服务。

I have read that it could be done using DOCKER_HOST, but if I configure /etc/default/docker with this variable, all the services would be run on the remote host, and what I need is some services in one remote host, and other services in other remote host.

推荐答案

在docker群模式下,您可以使用以下命令部署版本3的yml文件:

With docker swarm mode, you can deploy a version 3 compose yml file using:

docker stack deploy -c docker-compose.yml $your_stack_name

v3语法删除了一些不适用于群体模式的功能,像链接和依赖项。您还应该注意,默认情况下,卷存储在本地节点上。否则,v3语法与您可能已经在使用的v2语法非常相似。有关更多详细信息,请参见以太坊以下内容:

The v3 syntax removes a few features that do not apply to swarm mode, like links and dependencies. You should also note that volumes are stored local to a node by default. Otherwise the v3 syntax is very similar to the v2 syntax you may already be using. See ether following for more details:

https://docs.docker.com/compose/compose-file/

https://docs.docker.com/engine/swarm/

[docker-compose.yml v3之前的原始答案]

[ Original answer before v3 of the docker-compose.yml ]

要将单个docker-compose.yml部署到多个主机,您需要使用独立的群(不是较新的群模式,但是,这种模式正在迅速改变)。启动一个将每个主机定义为其群集成员的群集管理器,然后可以在docker-compose.yml中使用约束来定义哪些服务在哪些主机上运行。

For a single docker-compose.yml to deploy to multiple hosts, you need to use the standalone swarm (not the newer swarm mode, yet, this is rapidly changing). Spin up a swarm manager that has each host defined as members of its swarm, and then you can use constraints inside your docker-compose.yml to define which services run on which hosts.

您还可以将docker-compose.yml拆分为多个文件,每个主机一个,然后运行多个docker-compose up命令,为每个命令定义不同的DOCKER_HOST值。

You can also split up your docker-compose.yml into several files, one for each host, and then run multiple docker-compose up commands, with a different DOCKER_HOST value defined for each.

在两种情况下,您都需要配置docker安装程序以侦听网络,这应该通过在这些套接字上配置TLS来完成。 此文档描述了您需要执行的操作。

In both cases, you'll need to configure your docker installs to listen on the network, which should be done by configuring TLS on those sockets. This documentation describes what you need to do for that.

这篇关于Docker-compose:在多个主机中部署服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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