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

查看:114
本文介绍了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 swarm 模式,您可以使用以下命令部署版本 3 compose 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 语法删除了一些不适用于 swarm 模式的功能,例如链接和依赖项.您还应该注意,默认情况下,卷存储在节点的本地.否则 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 部署到多个主机,您需要使用独立的 swarm(不是较新的 swarm 模式,但这种模式正在迅速变化).启动一个群管理器,将每个主机定义为其群的成员,然后您可以使用 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天全站免登陆