I created a 4 micro-services using the Moleculer framework with docker-compose
. How do I statically configure each micro-service to run on a specific machine.
Asked
Active
Viewed 103 times
-1

Mostafa Hussein
- 11,063
- 3
- 36
- 61

Kell Maresh
- 13
- 7
-
How are you currently deploying them to different machines? Swarm mode, classic swarm, kubernetes? – BMitch Mar 07 '19 at 10:36
-
I haven't been able to deploy them to different machines yet. I was simply using docker-compose to run them on a single host. – Kell Maresh Mar 07 '19 at 11:16
-
@KellMaresh Have you checked my updated answer below ? – Mostafa Hussein Mar 07 '19 at 11:58
-
With docker-compose, everything runs on a single machine, so I don't understand the problem you are trying to solve. – BMitch Mar 07 '19 at 12:22
-
@BMitch I think his docker-compose contains 4 services. and he want to deploy each service on a separate / specific server/node so I suggested in my answer to use docker swarm along with `constraints` – Mostafa Hussein Mar 07 '19 at 12:30
-
1@MostafaHussein I'm not sure the open ended question is a good fit for the site. The OP should specify which orchestration tool they want to configure and ask how to configure that specific tool. With the current tool specified, they are already running containers on a specific node and should not be encountering any issues with containers running on unpredictable nodes. Overall, the request is an anti-pattern for containers since it reduces HA. – BMitch Mar 07 '19 at 12:54
-
You are correct!, I just assumed that there is no tool to configure, and only basic docker usage. so i thought I would suggest swarm as a guide to resolve the issue :D – Mostafa Hussein Mar 07 '19 at 12:58
1 Answers
0
You may want to use 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: What is the difference between docker host and node?
Constraints can be treated as node tags, They are key/value pairs associated to particular node.
Each node by default has the following constraints:
- node.id
- node.hostname
- node.role
A service can be deployed as the following:
docker service create --name backendapp --constraint 'node.hostname == web.example.com'
Note that you can deploy to swarm using docker-compose.yml
:
The deploy command supports compose file version 3.0 and above.
docker stack deploy --compose-file docker-compose.yml mystack
Also you can set constraints in docker-compose
similar to the following example:
version: '3.3'
services:
web:
image: backendapp-image
deploy:
placement:
constraints:
- node.hostname == web.example.com
You can get start with docker swarm through here

Mostafa Hussein
- 11,063
- 3
- 36
- 61
-
Thank you so much for the answer but from the looks of it, the scheduler filter would allow me to choose a specific type of node instead of a specific host to run the service. – Kell Maresh Mar 07 '19 at 09:38
-
it is a host, I have updated my answer, is this clear enough ? or you need more explanation ? – Mostafa Hussein Mar 07 '19 at 09:40
-
The available filters are: health, port, dependency, affinity and constraint. None of these would allow me to specify a specific host for a specific service. They would allow me to choose a specific type of host for a given service. – Kell Maresh Mar 07 '19 at 09:51
-
check the following: https://docs.docker.com/engine/reference/commandline/service_create/#specify-service-constraints---constraint – Mostafa Hussein Mar 07 '19 at 09:54
-
-
Is there an easier way to run any one of my micro-services on a specific host without using a tool like docker swarm (e.g only by changing configuration statically or something)? – Kell Maresh Mar 07 '19 at 15:12
-
No, the docker swarm is the starting point here. alternatively you can tread each host on its own (each host is a single docker host then connect all together) but using swarm is better as it provides more features against using single docker host – Mostafa Hussein Mar 07 '19 at 15:21