Node configuration

How to configure number of containers a node can run? For performance reasons, we want to limit the number of containers run on a node. For example

manager
worker 1 (node 1)

  • 3 containers (db)
    worker 2 (node 2)
  • 10 containers (apps)
    worker 3 (node 3)
  • 10 containers (apps)

Is it even possible to configure what service(s) get run on a node? For my example, I want all db containers to be on node 1.

Hello!

If you wanna choose a limited numbers of containers in a specific node, you need to set: docker node update --availability drain $NODE_NAME

You will set drain for all nodes and just 1 as --availability active . If you have just one node as active, the containers will be create just in that node but if you have or more as active, the docker swarm will share the containers for all hosts.

For example:

docker node update --availability active worker1 (don`t need set it, active is the default availability)
docker node update --availability drain worker2
docker node update --availability drain worker3

And now you can use: $ docker service create --replicas 3 -- name database db:latest

and you will have:

manager
worker 1 (node 1)

  • 3 containers (db)
    worker 2 (node 2)
  • 0 containers (apps)
    worker 3 (node 3)
  • 0 containers (apps)

then set:

docker node update --availability drain worker1 
docker node update --availability active worker2
docker node update --availability active worker3

And now you can use: $ docker service create --replicas 20 -- name my_app app:latest .

Docker swarm will share 10 containers for each node with the same app.

When everything is ok, set --availability active for all nodes.

With you have any questions, tell me.

Renan Pitz.