Single-node mode docker-swarm

Before reading this article, make sure you have the correct container of a machine and can be used docker-compose the deployment vessel. If not, please refer to the layout file .

A swarm cluster has two nodes, manager node and worker nodes. A container of the machine (may be a physical machine or a virtual machine) can be upgraded to a swarm node. The so-called swarm single-node model, is only a swarm cluster manager node.

Why should an ordinary container of machine upgraded to a swarm node it?

  • Ordinary machine only image of the container and container concept, introduced swarm node stack, service and task concepts easier to create, scale and manage the container, you can easily do load balancing.
    Here Insert Picture Description
  • After upgrading to swarm nodes, and other containers can together form the swarm cluster of machines, cross-node management.
//首先确保机器已经容器化,使用docker-machine创建或者Docker Desktop for **安装。
//将机器升级为swarm管理节点。
docker swarm init		//成功执行后,机器即升级为manager节点
//执行这句话之后可以得到一个token,后续凭借token和地址可以加入到集群中
docker swarm join --token ****** --listen-addr **
//如果忘记token,可以使用以下命令查询:
docker swarm join-token manager //加入管理节点token
docker swarm join-token worker //加入工作节点token
//管理节点的集群连接ip端口可以通过命令查询:
docker info

Through the above steps, a container of the machine can be upgraded to a swarm node.
Then refer docker-compose file syntax to write deployment configuration file, the following reference

//服务之间可以通过服务名来访问,无需links参数链接容器
version: "3.7"
networks:
  xxl:
    driver: overlay		//创建overlay网络
    ipam:
      driver: default
      config:
        - subnet: 172.18.0.0/16
services:
  nginx:
    image: nginx		//只能通过镜像来创建,不支持build参数
    networks:
      - xxl
    ports:
      - "0.0.0.0:80:80"
      - "0.0.0.0:443:443"
    volumes:
      - "./nginx/nginx.conf:/etc/nginx/nginx.conf:ro"
      - "./dist:/dist:ro"
    deploy:		//关键还是这个deploy参数,可以仔细看看
      replicas: 1
      placement:
        constraints:
          - node.role== manager
  redis:
    image: redis
    networks:
      - xxl
    ports:
      - "0.0.0.0:6379:6379"
    volumes:
      - "./redis/redis.conf:/etc/redis/redis.conf:ro"
      - "./redis:/data:rw"
    command: redis-server /etc/redis/redis.conf
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.role == manager
  mysql:
    image: xxl-mysql
    networks:
      - xxl
    ports:
      - "0.0.0.0:33060:3306"
    volumes:
      - "./mysql:/var/lib/mysql:rw"
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.role == manager
  rabbitmq:
    image: xxl-rabbitmq
    networks:
      - xxl
    ports:
      - "0.0.0.0:15672:15672"
      - "0.0.0.0:1883:1883"
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.role == manager
  nexus:
    image: sonatype/nexus3
    networks:
      - xxl
    ports:
      - "0.0.0.0:8081:8081"
    volumes:
      - "./nexus:/nexus-data:rw"
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.role == manager
  portainer:		//用于查看集群情况
    image: portainer/portainer
    networks:
      - xxl
    ports:
      - "0.0.0.0:8082:9000"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.role == manager

Yml then use the file to create containers, tasks, and stack services

//按照配置文件创建名为xxl的stack
docker stack deploy -c .\docker-compose.yml xxl
//移除名称为xxl的stack
docker stack rm xxl

Since the service added to portainer, you can visit http: // localhost: 8082 / # / home viewing cluster cases
Here Insert Picture Description
so far, the container of the machine + docker-compose deploy upgraded swarn single-node model success. Thus, no additional installation of a docker-compose.

Published 21 original articles · won praise 0 · Views 799

Guess you like

Origin blog.csdn.net/ssehs/article/details/104092139