Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not respecting Affinity Rules during Docker-Compose scale #112

Open
Smithx10 opened this issue Apr 15, 2017 · 3 comments
Open

Not respecting Affinity Rules during Docker-Compose scale #112

Smithx10 opened this issue Apr 15, 2017 · 3 comments

Comments

@Smithx10
Copy link

Smithx10 commented Apr 15, 2017

I've discovered if you create an affinity rule and run docker-compose scale consul=3 all 3 instances start on the same node.

(docker) [root@ws jenkins]# docker-compose scale consul=3
Creating and starting jenkins_consul_1 ... done
Creating and starting jenkins_consul_2 ... done
Creating and starting jenkins_consul_3 ... done
(docker) [root@ws jenkins]# triton insts -H -o name,compute_node | sort | uniq -c | sort | grep jenkins_consul
      1 jenkins_consul_1  a92fa576-c97b-0010-a443-c4544472c443
      1 jenkins_consul_2  a92fa576-c97b-0010-a443-c4544472c443
      1 jenkins_consul_3  a92fa576-c97b-0010-a443-c4544472c443

If I run docker-compose scale consul=1 && docker-compose scale consul=2 && docker-compose scale consul=3 they honor the affinity rules.

(docker) [root@ws jenkins]# docker-compose scale consul=1 && docker-compose scale consul=2 && docker-compose scale consul=3
Creating and starting jenkins_consul_1 ... done
Creating and starting jenkins_consul_2 ... done
Creating and starting jenkins_consul_3 ... done
(docker) [root@ws jenkins]# triton insts -H -o name,compute_node | sort | uniq -c | sort | grep jenkins_consul
      1 jenkins_consul_1  a92fa576-c97b-0010-a443-c4544472c443
      1 jenkins_consul_2  0a416e76-c97b-0010-bdb3-c4544472c3fc
      1 jenkins_consul_3  be233e0c-c67b-0010-82d4-c4544464394f

Docker-Compose.yml:

consul:
    image: autopilotpattern/consul:latest
    restart: always
    mem_limit: 128m
    ports:
      - 8500
    dns:
      - 127.0.0.1
    labels:
      - triton.cns.services=jenkins-consul
      - com.example.type=jenkins-consul
      - com.docker.swarm.affinities=["com.example.type!=jenkins-consul"]
    command: >
      /usr/local/bin/containerpilot
      /bin/consul agent -server
        -bootstrap-expect 3
        -config-dir=/etc/consul
        -ui-dir /ui
@Smithx10
Copy link
Author

Smithx10 commented Apr 15, 2017

After reading through ./lib/backends/sdc/affinity.js, I think we are only checking what is currently running and handing it off to DAPI. This explains why when submitted at the same time the services are landing on the same computenode.

@papertigers
Copy link
Contributor

papertigers commented Apr 20, 2017

Hey, you likely want:

com.docker.swarm.affinities=["com.example.type!=jenkins-consul*"]

In your example you are trying to match "jenkins-consul" exactly.

Check out https://apidocs.joyent.com/docker/features/placement

Edit:
Didn't notice this was a label filter and not container. Let me gather some more data.

@papertigers
Copy link
Contributor

Filed internally as
https://smartos.org/bugview/DOCKER-1039

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants