{"action":"created","issue":{"url":"https://api.github.com/repos/docker/compose/issues/1234","labels_url":"https://api.github.com/repos/docker/compose/issues/1234/labels{/name}","comments_url":"https://api.github.com/repos/docker/compose/issues/1234/comments","events_url":"https://api.github.com/repos/docker/compose/issues/1234/events","html_url":"https://github.com/docker/compose/issues/1234","id":65599224,"number":1234,"title":"Proposal: Support for affinity filter in Docker Swarm","user":{"login":"denverdino","id":409721,"avatar_url":"https://avatars.githubusercontent.com/u/409721?v=3","gravatar_id":"","url":"https://api.github.com/users/denverdino","html_url":"https://github.com/denverdino","followers_url":"https://api.github.com/users/denverdino/followers","following_url":"https://api.github.com/users/denverdino/following{/other_user}","gists_url":"https://api.github.com/users/denverdino/gists{/gist_id}","starred_url":"https://api.github.com/users/denverdino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denverdino/subscriptions","organizations_url":"https://api.github.com/users/denverdino/orgs","repos_url":"https://api.github.com/users/denverdino/repos","events_url":"https://api.github.com/users/denverdino/events{/privacy}","received_events_url":"https://api.github.com/users/denverdino/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/docker/compose/labels/area/up","name":"area/up","color":"c7def8"},{"url":"https://api.github.com/repos/docker/compose/labels/kind/feature","name":"kind/feature","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-01T03:52:08Z","updated_at":"2015-10-12T01:36:35Z","closed_at":null,"body":"Swarm provide the container affinity to control the placement of container with the environment variables as following\r\n\r\nE.g. \r\n```\r\naffinity:container==[<container_name>|<regexp>]\r\naffinity:container!=[<container_name>|<regexp>]\r\naffinity:container==~[<container_name>|<regexp>]\r\naffinity:container!=~[<container_name>|<regexp>]\r\n```\r\nThe challenge to use the affinity in the Compose template are\r\n1. The container name is generated with service name and project name. It is not easy to write above filter easily. \r\n\r\nPropose to use bellow way to describe the container affinity for specific service. And it will be converted to the \"affinity:container\" when create/recreate the container\r\n```\r\naffinity:service==<service_name>\r\naffinity:service!=<service_name>\r\naffinity:service==~<service_name>\r\naffinity:service!=~<service_name>\r\n```\r\nE.g. the following compose template to deploy the containers of \"web\" and \"test\" service in different hosts.\r\n```\r\nweb:\r\n  image: nginx\r\n  ports:\r\n    - 80\r\ntest:\r\n  image: nginx\r\n  ports:\r\n    - 80\r\n  environment:\r\n    - affinity:service!=~web\r\n```\r\n\r\n2. The implied affinity relationship between service should be considered.\r\n\r\nE.g. for above sample, if we recreate the container for \"web\" service. It will be better to consider the affinity filer of \"test\". Otherwise, the new container may break the expectation for the placement.\r\n\r\nSo if service \"A\" has the affinity condition with \"B\", the \"B\" should have the same affinity condition with \"A\"\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/docker/compose/issues/comments/147271712","html_url":"https://github.com/docker/compose/issues/1234#issuecomment-147271712","issue_url":"https://api.github.com/repos/docker/compose/issues/1234","id":147271712,"user":{"login":"denverdino","id":409721,"avatar_url":"https://avatars.githubusercontent.com/u/409721?v=3","gravatar_id":"","url":"https://api.github.com/users/denverdino","html_url":"https://github.com/denverdino","followers_url":"https://api.github.com/users/denverdino/followers","following_url":"https://api.github.com/users/denverdino/following{/other_user}","gists_url":"https://api.github.com/users/denverdino/gists{/gist_id}","starred_url":"https://api.github.com/users/denverdino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denverdino/subscriptions","organizations_url":"https://api.github.com/users/denverdino/orgs","repos_url":"https://api.github.com/users/denverdino/repos","events_url":"https://api.github.com/users/denverdino/events{/privacy}","received_events_url":"https://api.github.com/users/denverdino/received_events","type":"User","site_admin":false},"created_at":"2015-10-12T01:36:35Z","updated_at":"2015-10-12T01:36:35Z","body":"@dnephin Daniel, using the label filter will be good from the implementation point of view. The challenge is the docker-compose  \r\n"}}