在特定机器上将微服务静态配置为 运行
Statically configure a microservice to run on a specific machine
我使用 docker-compose
的 Moleculer 框架创建了 4 个微服务。如何在特定机器上将每个微服务静态配置为 运行。
您可能想要使用 docker swarm which has a feature allows you to deploy a container on a specific node which called Constraints
Node: A docker node refers to a member in a swarm mode cluster. Every swarm node must be a docker host, Source:
约束可以被视为节点标签,它们是 key/value 对与特定节点相关联。
默认情况下每个节点都有以下约束:
- node.id
- node.hostname
- node.role
可以按如下方式部署服务:
docker service create --name backendapp --constraint 'node.hostname == web.example.com'
请注意,您可以使用 docker-compose.yml
:
部署到 swarm
The deploy command supports compose file version 3.0 and above.
docker stack deploy --compose-file docker-compose.yml mystack
您还可以在 docker-compose
中设置约束,类似于以下示例:
version: '3.3'
services:
web:
image: backendapp-image
deploy:
placement:
constraints:
- node.hostname == web.example.com
你可以开始 docker swarm through here
我使用 docker-compose
的 Moleculer 框架创建了 4 个微服务。如何在特定机器上将每个微服务静态配置为 运行。
您可能想要使用 docker swarm which has a feature allows you to deploy a container on a specific node which called Constraints
Node: A docker node refers to a member in a swarm mode cluster. Every swarm node must be a docker host, Source:
约束可以被视为节点标签,它们是 key/value 对与特定节点相关联。
默认情况下每个节点都有以下约束:
- node.id
- node.hostname
- node.role
可以按如下方式部署服务:
docker service create --name backendapp --constraint 'node.hostname == web.example.com'
请注意,您可以使用 docker-compose.yml
:
The deploy command supports compose file version 3.0 and above.
docker stack deploy --compose-file docker-compose.yml mystack
您还可以在 docker-compose
中设置约束,类似于以下示例:
version: '3.3'
services:
web:
image: backendapp-image
deploy:
placement:
constraints:
- node.hostname == web.example.com
你可以开始 docker swarm through here