Docker Swarm

Docker Swarm Initialization

1.Install Docker and initial

Skip

2. Initialize Docker Swarm Cluster

Select everyone to set up cluster.

docker swarm init --advertise-addr <cluster_ip>        

You can get a swarm token like this?ddocker swarm join --token SWMTKN-1-2142i8zn <cluster_ip>:2377

  • If you want?mutiple managers, use?docker swarm join-token manager?to get manager token.?docker swarm join-token worker?to get worker token.
  • We can also use?docker node promote <NODE_NAME>?to promote a node to manager.

3. Add Nodes

Use?docker swarm join --token SWMTKN-1-2142i8zn <cluster_ip>:2377?to add nodes.

4. Remove Nodes

Use?docker swarm leave?to remove nodes.

5. View Nodes and Services

Use?docker node ls?to view nodes. Use?docker service ls?to view services.

Docker Swarm Configuration Examples

1. Create a nginx service

docker service create --name test-nginx --publish 80:80 --replicas 3 nginx        

2. Check service status

docker service ls
docker service ps test-nginx # check nginx service        

3. Scale service

docker service scale test-nginx=5        

4. Remove service

docker service rm test-nginx        

Docker Swarm Compose

1. Docker Compose file

version: '3.8'

services:
  web:
    image: nginx:latest
    hostname: "{{.Service.Name}}-{{.Task.Slot}}"
    ports:
      - "80:80"
    deploy:
      replicas: 3
      restart_policy:
        condition: on-failure
      placement:
        constraints:
          - node.role == worker
    networks:
      - webnet

networks:
  webnet:        

placement.constraints means the node must be a worker node. It is optional.

2. Run Compose

docker stack deploy -c docker-compose.yaml test_nginx        

3. Change replicas number

Modify replicas number in docker-compose.yaml, and run Compose again.

docker stack deploy -c docker-compose.yaml test_nginx        

4. Remove Compose

docker stack rm test_nginx        

要查看或添加评论,请登录

Jiangbo Li的更多文章

  • About CIDR

    About CIDR

    What is 10.105.

  • Start from Hashicorp Vault

    Start from Hashicorp Vault

    What is the Hashicorp Vault key feature HashiCorp Vault is an open-source tool designed for securely managing secrets…

  • About CI/CD

    About CI/CD

    What is you want about CI/CD Safe Reversible Provide no down time Deployment Rolling Deploymen(Phased Deployment)…

  • Ansible install docker to Ubuntu

    Ansible install docker to Ubuntu

    About ansible Ansible is a radically simple IT automation system. It handles configuration management, application…

  • Linux chattr command

    Linux chattr command

    chattr (Change Attribute) is a command line Linux utility that is used to set/unset certain attributes to a file in…

  • Setup Webdav using Caddy at Ubuntu

    Setup Webdav using Caddy at Ubuntu

    Install Caddy Server Please see this link https://caddyserver.com/docs/install Install Caddy Webdav module Configuring…

  • Notification when ssh login

    Notification when ssh login

    I want to keep an eye on SSH logins to a particular server. For this, I've opted for the 'ntfy' service to send push…

社区洞察

其他会员也浏览了