title: Control distribution of docker swarm services across different computers?
body: <p>Is there a way to control the distribution of services across different computers? I have one master with two workers and 5 services:</p>
  <ul>
  <li>web server</li>
  <li>database</li>
  <li>redis</li>
  <li>celery</li>
  <li>s3 storage connection</li>
  </ul>
  <p>I only want to outsource the celery workers and run everything else on the master. Is there a way to control that with <code>docker swarm</code>? I have not created a registry yet, because I am not sure if that is still necessary.</p>
  <p>Here is my current <strong>experimental</strong> docker-compose file.</p>
  <pre><code>version: &quot;3.8&quot;
   
  volumes:
    s3data:
      driver: local
  
  services:
    web:
      image: localhost:5000/web
      build: .
      env_file:
        - ./.env
      environment:
        - ENVIRONMENT=develop
      command: python manage.py runserver 0.0.0.0:8000
      volumes:
        - ./app/:/app/
        - ./lib/lrg_omics/:/lrg-omics/
        - s3data:/datalake/
        - /data/media/:/appmedia/
        - /data/static/:/static/
      ports:
        - &quot;8000:8000&quot;
      depends_on:
        - db
        - redis
        - s3vol
      links:
        - redis:redis
      restart: always
    
    db:
      image: postgres
      volumes:
        - /data/db/:/var/lib/postgresql/data
      environment:
        - POSTGRES_DB=postgres
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=postgres
  
    redis:
      restart: always
      image: redis:alpine
      ports:
        - &quot;6379:6379&quot;
  
    celery:
      restart: on-failure
      image: pp-celery-worker
      build:
        context: .
        dockerfile: Dockerfile
      command: bash -c &quot;celery -A main worker -l info --concurrency 8&quot;
      env_file:
        - ./.env    
      volumes:
        - ./app/:/app/
        - ./lib/lrg_omics/:/lrg-omics/
        - s3data:/datalake/      
      environment:
        - DB_HOST=db
        - DB_NAME=app
        - DB_USER=postgres
        - DB_PASS=postgres
      depends_on:
        - db
        - redis
        - web
        - s3vol
      deploy:
        replicas: 2
        placement:
          max_replicas_per_node: 1
  
  
    s3vol:
      image: elementar/s3-volume
      command: /data s3://PQC
      environment:
        - BACKUP_INTERVAL=2
        - AWS_ACCESS_KEY_ID=...
        - AWS_SECRET_ACCESS_KEY=...
        - ENDPOINT_URL=https://example.com
      volumes:
        - s3data:/data
      
  </code></pre>
  <p>When I deploy this with <code>sudo docker stack deploy --compose-file docker-compose-distributed.yml QC</code></p>
  <p>And then look at the services I get something like this:</p>
  <pre><code>sudo docker stack services QC
  &gt;&gt;&gt;
  ID             NAME        MODE         REPLICAS               IMAGE                        PORTS
  xx5hkbswipoz   QC_celery   replicated   0/2 (max 1 per node)   celery-worker:latest         
  natb3trv9ngi   QC_db       replicated   0/1                    postgres:latest              
  1bxpkb18ojay   QC_redis    replicated   1/1                    redis:alpine                 *:6379-&gt;6379/tcp
  6rsl5gfpd0oa   QC_s3vol    replicated   1/1                    elementar/s3-volume:latest   
  aszkle6msmqr   QC_web      replicated   0/1                    localhost:5000/web:latest    *:8000-&gt;8000/tcp
  </code></pre>
  <p>For some reason only <code>redis</code> and the <code>S3</code> containers run. And both of them on the master. Nothing runs on the workers.</p>
  <p>I am quite new to <code>docker swarm</code> so there is probably more than one thing wrong here. Any comments on best practices are welcome.</p>