Docker Community Forums

Share and learn in the Docker community.

`docker-compose up` ignores affinities and constraints


(Dennis W) #1

Goal
Running Docker 1.11.2 and docker-compose 1.8.0 (problem persists after downgrading to 1.7.0), I try to update a service in a Docker 1.11.2 Swarm cluster of three nodes. The services in my docker-compose.yml have affinities to ensure that one container of each service is deployed on each node.

The compose-file

services:
  service1:
    image: myimage1:latest
    environment:
    - "affinity:com.mycompany.type!=~service1"
    - "affinity:container!=~*service1_*"
    labels:
    - "com.mycompany.type=service1"

  service2:
    image: myimage2:latest
    environment:
    - "affinity:com.mycompany.type!=~service2"
    - "affinity:container!=~*service2_*"
    labels:
    - "com.mycompany.type=service2"

Problem
This works well on initial start:

docker-compose -p myproject scale service1=3 service2=3

distributes both services nicely. But when I try to update the project, docker-compose -p myproject up -d places all recreated containers randomly on the nodes, ignoring what I definied as affinities. :sweat:

Has anyone a nice idea on how to fix this behavior?


(Nathan Le Claire) #2

Mind opening an issue at https://github.com/docker/compose/issues/new ? The forum is meant for more general discussion than specific bug reporting


(Dennis W) #3

Sure. Did that.