Skip to content

Docker Swarm

Docker Swarm management

Init Docker Swarm

docker swarm init

Nodes Management

List Nodes

# list nodes
docker node ls

ID                            HOSTNAME                     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
6ksl1n3ur4dcpnhqddftjlu7z     oci-e003kurian-arm-nonfree   Ready     Active                          23.0.4
v9wn0ounr061itvojddj41mmw *   oci-e003kurian-mainarm       Ready     Active         Leader           23.0.4
lgwenxg6rhjj78usmg0glkx5f     oci-e003kurian-x86-01        Down      Active                          23.0.4
wiuw5gulea346totcqgb55qvu     oci-e003kurian-x86-02        Down      Active                          23.0.4

Get Join Tocken

docker swarm join-token worker

Add Worker Node

docker swarm join --token SWMTKN-1-1xo8rcekxfge5xvznfffqoab7gk1hd7gxwy7capb77zoysz6vs-85koyursclly99g71o4pzns99 100.123.167.124:2377

Remove Worker Node

docker node rm <nodeid>

Remove All Nodes

sudo docker node rm $(sudo docker node ls | grep Down | awk -F" " '{ print $1 }')

Leave Swarm

docker swarm leave

Service Management

List Services

docker service ls

List Containers

docker node ps $(docker node ls -q)

Rebalance Services

docker service update --force service_name

Sample New Relic Service

Deploy

deploy:
  replicas: 15
  placement:
    max_replicas_per_node: 1
  update_config:
    parallelism: 1
    order: start-first
version: "3.9"
services:
    infrastructure:
        container_name: newrelic-infra
        restart: unless-stopped
        network_mode: host
        privileged: true
        pid: host
        volumes:
            - '/:/host:ro'
            - '/var/run/docker.sock:/var/run/docker.sock'
        environment:
            - NRIA_LICENSE_KEY=***
        image: 'newrelic/infrastructure:latest'
        networks:
          - outside
        deploy:
          replicas: 15
          placement:
            max_replicas_per_node: 1
          update_config:
            parallelism: 1
            order: start-first

networks:
  outside:
    external:
      name: "host"