Docker Community Forums

Share and learn in the Docker community.

Docker swarm constraints being ignored


(Junius) #21

Not sure if node.hostname constraint works or not. You could try to add label to the node, follow swarm add or remove label. For example, you could add docker node update --label-add zknode1=mynode1 node-1 to the first node. Then

services:
  dev2-1:
    image: ourrepo/me/zookeeper:3.4.10
    ports:
     - "22281:2181"
     - "22282:2888"
     - "22283:3888"
    environment:
     - "ZOOKEEPER_ID=1"
     - "ZOOKEEPER_SERVERS=mynode1,mynode2,mynode3"
     - "leaderPort=22282"
     - "electionPort=22283"
    volumes:
     - /app/zookeeper-dev2/lib:/var/lib/zookeeper
     - /app/zookeeper-dev2/log:/var/log/zookeeper
    deploy:
      mode: global
      placement:
        constraints:
         - node.labels.zknode1 == mynode1

Follow it for ndoe2 and 3 as well.


(Mahendral) #22

If you are using ‘docker-compose up -d’

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use docker stack deploy.


(Santhosh Kani S) #23

I am able to bring up zookeeper instance on unique nodes participated in docker swarm.
Refer my comment on following discussion thread.