<!-- TITLE: Swarm Cluster --> <!-- SUBTITLE: A quick summary of Swarm Cluster --> # SWARM Cluster Setup and Deploy ## Initalization ```sh sudo docker swarm init --advertise-addr VM_IP_ADDRESS ``` ## Run with Docker-Compose configuration and .env file ```sh sudo env $(sudo cat .env | grep ^[A-Z] | xargs) docker stack deploy --with-registry-auth --compose-file docker-compose.yml project_name ``` ## Networks Use only overlay network to run in cluster mode. If exact network is defined in docker-compose file, like bridge network, it should be created as follows. *Skip if overlay is used.* ``` sudo docker network create \ --subnet 10.10.1.0/24 \ --gateway 10.10.1.1 \ -o com.docker.network.bridge.enable_icc=false \ -o com.docker.network.bridge.name=docker_gwbridge \ docker_gwbridge ``` ## Publish/Expose cluster ports ``` docker service update \ --publish-add published=80,target=3000 \ project_name_backend ``` ## Scale Backend service for Zero-Downtime deployments ``` docker service scale project_name_backend=2 ``` ## Set HealthCheck to verify Backend is up and running Check curl is installed in the Backend image. Also check the backend port. ``` docker service update --health-cmd='curl -sS 127.0.0.1:3000 || exit 1' project_name_backend ``` ## Set Rolling Update parameters ``` docker service update --update-parallelism 1 --update-delay 15s --update-order start-first project_name_backend ``` ## Perform Rolling Update ``` docker service update --force --image hub.shakuro.com/template/backend:20190514135602 project_name_backend ``` ## Change service startup command ``` docker service update --args "bash -c 'nginx && NODE_ENV=production PORT=4200 node dist/server'" project_name_backend ```