Dustin
Dustin

Reputation: 6307

Docker Swarm - Schedule container on each machine

I'm currently trying to spawn a container instance of Redis separately on each cluster machine using Docker Swarm/Compose. I'm currently using 4 machines for the example. Using the affinity labels, the idea was to make sure two redis instances wouldn't get scheduled on to the same machine.

At first, the following worked.

redis:
  image: redis
  environment:
    AFFINITY: com.myself.name!=redis
  labels:
    - "com.myself.name=redis"

However after forcing some containers to stop to simulate crashes, pushing them back, turning all containers off, and then finally running everything from the start again using docker-compose scale redis=4, I find redis running two containers on the same machine even though there's 4 available in the cluster.

What exactly am I doing wrong? Thanks.

Upvotes: 4

Views: 849

Answers (2)

JorelC
JorelC

Reputation: 787

You should try this:

redis:
  image: redis
  environment:
    - "affinity:container!=*redis*"
  labels:
    - "com.myself.name=redis"

This should work!

Please, let me know

Upvotes: 4

Mark O'Connor
Mark O'Connor

Reputation: 78021

Try this docker compose file

redis:
  image: redis
  environment:
    - affinity:com.myself.name!=redis
  labels:
    - "com.myself.name=redis"

Upvotes: 0

Related Questions