[英]How to use Docker Compose with legacy Docker Swarm
I am trying to deploy my app with Compose
and Swarm
. 我正在尝试使用Compose
和Swarm
部署我的应用程序。 Currently I don't want to upgrade my docker-compose.yaml
from v2
to v3
. 目前,我不想将docker-compose.yaml
从v2
升级到v3
。 So I am only able to do that with standalone(legacy) swarm
rather that docker swarm mode
based on Stoneman's answer and official Swarm documents. 因此,我只能使用standalone(legacy) swarm
而不是基于Stoneman的答案和官方Swarm文档的docker swarm mode
来做到这一点。
Following the official instruction , I successfully set up a swarm cluster. 按照官方指示 ,我成功地建立了群集集群。 I ran docker -H :4000 info
on the swarm manager
node to check the swarm cluster status, as shown below. 我在swarm manager
节点上运行了docker -H :4000 info
来检查swarm集群的状态,如下所示。 There are two other worker nodes in this cluster. 该集群中还有两个其他工作节点。 Next, I want to create
an overlay network with this cluster and refer this network in the docker-compose.yaml
. 接下来,我想使用该集群create
一个覆盖网络,并在docker-compose.yaml
引用该网络。 But when I ran docker -H :4000 network create -d overlay test
on the swarm manager node to create the netwrok, it reported error: Error response from daemon: Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
但是,当我在群集管理器节点上运行docker -H :4000 network create -d overlay test
以创建netwrok时,它报告了错误: Error response from daemon: Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
Error response from daemon: Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
So, how can I create a network with a swarm cluster( without docker-machine
and virtual box
)? 那么,如何创建具有群集集群的网络(没有docker-machine
和virtual box
)? Currently, the swarm manager and worker nodes are running as docker containers. 当前,群集管理器和工作程序节点正在作为docker容器运行。
Did you setup overlay networking with it's own etcd backend first? 您是否首先使用自己的etcd后端设置了覆盖网络? https://docs.docker.com/network/overlay-standalone.swarm/ https://docs.docker.com/network/overlay-standalone.swarm/
Swarm "classic" is deprecated and replaced by docker swarm mode. Swarm“经典”已弃用,并由docker swarm模式取代。 Everything is harder in classic, including setting up overlay. 包括设置叠加层在内,一切都变得更困难。 I wouldn't recommend using it for anything new unless you had a hard requirement. 除非您有严格的要求,否则我建议您不要将它用于任何新事物。
In swarm mode you run all commands at the swarm manager host. 在群集模式下,您可以在群集管理器主机上运行所有命令。 Same with creating networks, secrets, etc. You can find out the docker manager machine by: $docker node ls Manager host is marked with MANAGER STATUS:Leader. 与创建网络,机密等相同。您可以通过以下方式找到Docker管理器计算机:$ docker node ls管理器主机已标记为MANAGER STATUS:Leader。 After creating the network on the manager all nodes on that swarm should see the network. 在管理器上创建网络后,该群集上的所有节点都应看到该网络。
"I ran docker -H :4000 network create -d overlay test" Better to declare the network inside the stack yml file, for faster and easier deployment. “我运行了docker -H:4000网络创建-d覆盖测试”最好在yml文件堆栈中声明网络,以便更快,更轻松地进行部署。 you can create network and expose your ports at the yml file, no need to create them manually every time you run the stack. 您可以创建网络并在yml文件中公开端口,而无需在每次运行堆栈时手动创建它们。 Add the following block under the docker service: 在docker服务下添加以下代码块:
services:
...
#Network
networks:
- network-name-here
...
#Exposed ports:
ports:
- target: 4000
published: 4000
At the end of the yml file add the following block to declare the network, so its created every time you run $docker stack deploy: 在yml文件的末尾添加以下块以声明网络,因此每次运行$ docker stack deploy时都会创建该网络:
networks:
network-name-here:
driver: overlay
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.