Reputation: 1082
I am new in Docker, and I was wondering a question today. I know there are spread and binpack strategies which are intends to balance the "work load". But is there any way to provision the containers like the following topology by using Docker, Swarm?
Or should I customize the scheduler? Or is there any suitable cluster management tool? And is there any suggestion?
Upvotes: 1
Views: 286
Reputation: 3439
Update: This answer applies to the legacy docker/swarm and not to the new Swarm mode available since docker 1.12
You can achieve this with Swarm through labels
when starting docker daemons on those racks/machines.
Assuming we have this topology:
rack1
|___ node1
rack2
|___ node2
|___ node3
We can setup the docker daemons with custom labels to reflect this:
Node 1 on Rack 1
docker --tlsverify --tlscacert=ca.pem --tlscert=server-cert.pem --tlskey=server-key.pem -H tcp://0.0.0.0:2376 -d --label rack=rack1 --label machine=node1`
Node 2 on Rack 2
docker --tlsverify --tlscacert=ca.pem --tlscert=server-cert.pem --tlskey=server-key.pem -H tcp://0.0.0.0:2376 -d --label rack=rack2 --label machine=node2
Node 3 on Rack 2
docker --tlsverify --tlscacert=ca.pem --tlscert=server-cert.pem --tlskey=server-key.pem -H tcp://0.0.0.0:2376 -d --label rack=rack2 --label machine=node3
With Swarm you can then use constraints to pick up a location for your containers. In this example, we only use the subset of nodes on Rack 1 to schedule our container:
docker run -d -P -e constraint:rack==rack1 --name web nginx
Providing that you have multiple nodes per rack (with rack2
for example) you can also chain constraints. In the next example, we pin the container to node3
which is located on rack2
.
docker run -d -P -e constraint:rack==rack2 -e constraint:node==node3 --name web nginx
Upvotes: 3