简体   繁体   中英

Docker swarm does not distribute the container in the cluster

I have a two servers to use in a Docker cluster Swarm(test only), one is a Manager and other is a Worker, but running the command docker stack deploy --compose-file docker-compose.yml teste2 all the services is run in the manager and the worker not receive the containers to run, for some reason the Swarm is not achieving distributing the services in the cluster and running all in manager server.

Will my docker-compose.yml be causing the problem or might it be a network problem?

Here are some settings:

  • Servers CentOs 7, Docker version 18.09.4;
  • I executed the commands systemctl stop firewalld && systemctl disable firewalld to disable firewall;
  • I executed the command docker swarm join --token ... in the worker;
  • Result docker node ls :

     ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION 993dko0vu6vlxjc0pyecrjeh0 * name.server.manager Ready Active Leader 18.09.4 2fn36s94wjnu3nei75ymeuitr name.server.worker Ready Active 18.09.4
  • File docker-compose.yml:

     version: "3" services: web: image: testehello deploy: replicas: 5 update_config: parallelism: 2 delay: 10s restart_policy: condition: on-failure # placement: # constraints: [node.role == worker] ports: - 4000:80 networks: - webnet visualizer: image: dockersamples/visualizer:stable ports: - 8080:8080 stop_grace_period: 1m30s volumes: - "/var/run/docker.sock:/var/run/docker.sock" deploy: placement: constraints: [node.role == manager] networks: webnet:
  • I executed the command docker stack deploy --compose-file docker-compose.yml teste2

In the docker-compose.yml I commented the parameters placement and constraints because they did not work and did not start the containers on the servers, without it the containers are started in the manager. Through the Visualizer all appear in the manager.

First, try to deploy without an update option, like:

version: "3.2"

services:
    web:
        image: testehello
        networks:
            - webnet
        deploy:
            mode: replicated
            replicas: 2
            placement:
                constraints: [node.role == worker]
        restart: unless-stopped
        logging:
            options:
                max-size: 1m

networks:
    webnet:
        external: true

Next, try to add an update option:

version: "3.2"

services:
    web:
        image: testehello
        networks:
            - webnet
        deploy:
            mode: replicated
            replicas: 2
            placement:
                constraints: [node.role == worker]
        update_config:
            parallelism: 1
            delay: 10s
        restart: unless-stopped
        logging:
            options:
                max-size: 1m

networks:
    webnet:
        external: true

I think the images are not accessible from a worker node, that is why they not receive containers, try to use this guide by docker https://docs.docker.com/engine/swarm/stack-deploy/

PS I think you solved it already, but just in case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM