First, create a cluster
1. Initialize the manager node (XXX is the manager's IP address)
docker swarm init --advertise-addr xxx.xxx.xxx.xxx
Will output the following, note Bold Italic command, join the cluster need to use
Swarm initialized:current Node (pk4p936t4e03cpse3izuws07s) is now a manager.
To add a worker to this swarm, run the following command:
Docker swarm join--token XXX xxx.xxx.xxx.xxx:2377
To add a manager to this swarm, run ' Docker swarm Join-token Manager ' and follow the instructions.
2, the worker joins the cluster, runs the above command on the other Docker server
docker swarm join --token xxx xxx.xxx.xxx.xxx:2377
3. View cluster status
docker node ls
Second, installation Portainer
1. Create a portainer-stack.yml file
version: ‘3‘services: portainer: image: portainer/portainer volumes: - "/var/run/docker.sock:/var/run/docker.sock" - "/data/portainer:/data" deploy: placement: constraints: [node.role == manager] # 控制管理界面部署在manager上 replicas: 1 restart_policy: condition: on-failure resources: limits: cpus: "0.2" memory: 200M labels: [svc=portainer] ports: - 9000:9000
2. Start Portainer Service
docker stack deploy -c portainer-stack.yml portainer
3, Access Portainer and change the password (XXX for any one of the cluster ip,swarm will automatically do load balancing)
Visit http://xxx.xxx.xxx.xxx:9000
Centos7 Configuring Docker Swarm and Installation Portainer