Search code examples
dockerdocker-swarm

How to setup docker swarm in distributed server?


I have set up single host docker deployment using docker-compose. But now I have 4 server instances running on vultr each one has different services running. For example,

Server 1: mongodb

Server 2: node/express

Server 3: redux

Server 4: load balancer

How can I connect all these services using docker swarm?


Solution

    • You should create swarm of nodes using docker swarm init and docker swarm join. Each node is docker engine installed on a different host. If you have just 4 hosts you can decide that all nodes will be managers.

    • Then you should deploy docker stack which will deploy your docker services (mongodb, etc...) using the docker-compose.yml file: docker stack deploy --compose-file docker-compose.yml

    • Docker services will run on all nodes according to the number of replicas you specify when you create each service.

    • If you want each service to run on specific node, assign labels for each node and add service constraints.