Linux/Docker/Swarm

From Wiki
< Linux‎ | Docker
Revision as of 19:52, 10 December 2021 by Marcluer (talk | contribs) (→‎Enable local insecure HTTP registry)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Create swarm

  • on manager
docker swarm init --advertise-addr <MANAGER-IP>

-> copy command from here to join from nodes. e.g.:
docker swarm join --token SWMTKN-1-5fs8k04yvhalpcok7xa8ktryuin55w4gt1wf1aaj9vawwh52hx-1uk9i6yz3q7j7bzuqdun2xqwy 192.168.1.226:2377
  • show token
docker swarm join-token manager

Stats / Info

docker node ls

docker service ls

docker service inspect service1 --pretty

docker node ps node1 node2 node3

Manage nodes

from manager:
docker node promote node1
docker node demote node1
docker node rm node1
docker node inspect node1
docker node inspect --pretty node1
docker node update --role manager node1

docker node update --availability drain node1    # pause node and move load to other nodes
docker node update --availability active node1   # unpause and send back to work


from node:
docker swarm leave

Services

docker service create --replicas 4 --name service1 alpine ping google.com

docker service ls                                # list services
docker service ps service1                       # list instances of service on nodes
docker service logs service1 -f

docker service scale service1=0
docker service rm service1

docker service update --image alpine service1

Enable local insecure HTTP registry

echo '''{ "insecure-registries": [ "vm-docker0:5000" ] }''' > /etc/docker/daemon.json 

Stack

  • docker-compose.yml
version: '3.9'

services:
  http:
    image: nginxdemos/hello:latest
    ports:
      - "80:80"
    deploy:
      replicas: 4
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure
      resources:
        limits:
          cpus: "0.1"
          memory: 1G


docker stack deploy -c docker-compose.yml hello

docker stack ls
docker stack ps hello
docker stack services hello

docker stack rm hello