Swarm Introduction
Since its inception, the container features and mirroring features of Docker have brought a lot of convenience to devops enthusiasts. For a long time, however, Docker can only run on a single host, and its ability to deploy, run, and manage across hosts has been widely criticized. The weak cross-host capability leads directly to the tight coupling between the Docker container and the host, in which case the flexibility of the Docker container is very difficult, and the migration, grouping, etc. of the containers becomes a very difficult function point to implement.
Swarm is a new container management tool released by Docker in early December 2014. The Docker management tools released with Swarm are also machine and compose.
Swarm is a relatively simple set of tools for managing Docker clusters, making the Docker cluster exposed to users as a virtual whole. Swarm uses the standard Docker API interface as its front-end access portal, in other words, the various forms of Docker Client (dockerclient in Go, docker_py, Docker, etc.) can communicate directly with swarm. Swarm is almost entirely developed in the go language and is still in an alpha version, and the version currently available on GitHub is only v0.1.0-rc1. However, the development of swarm is very fast, and the change of function and characteristic is very frequent. Therefore, it can be said that swarm is not recommended for use in production environments, but it is certain that swarm is a promising technology. Port Monitoring
The swarm is communicated by listening on port 2375, so you need to set up 2375-port monitoring before using Swarm for cluster management. There are two ways to do this, either by modifying the Docker configuration file, or by listening through a lightweight proxy container. Modify configuration file Modify listening port (recommended)
Since I am using CENTOS7 to install Docker, the following configuration is available for CENTOS7.
Open the configuration file/etc/sysconfig/docker:
Vim/etc/sysconfig/docker
Modify the values in the Configuration items options, add the-H tcp://0.0.0.0:2375-h unix:///var/run/docker.sock directly if there are no values in the options, or add them after the existing parameters, such as the following:
Options= '--selinux-enabled--log-driver=journald
--signature-verification=false-
H tcp://0.0.0.0:2375-h Unix:///var/run/docker.sock '
Save the file after you modify it, and then restart the Docker service
Systemctl Restart Docker
Note: The above modification of the configuration file is required for all Docker nodes to be joined to the cluster. using the Docker-proxy Proxy service
By default, the Docker engine listens only for sockets. We can reconfigure the engine to use TLS, or you can use the proxy container. This is a very lightweight container that simply forwards requests from TCP to a UNIX socket for Docker snooping.
Download the image from the Docker pull command first
Docker Pull Docker.io/shipyard/docker-proxy
Then start the container:
Docker run-ti-d-P 2375:2375 \
--restart=always \
--hostname= $HOSTNAME \
--name shipyard-proxy \
-v/va R/run/docker.sock:/var/run/docker.sock \-
e port=2375 \
docker.io/shipyard/docker-proxy:latest
Note: The Proxy service container also needs to be started on each Docker node to be joined to the cluster, ensuring that the container is functioning properly and that the node cannot be discovered if the container is stopped. build Docker cluster pull swarm image
Docker Pull Docker.io/swarm
Generate unique token
Create a world-wide unique token (cluster ID) on any Docker node, remembering that this token needs to be used later. (The discovery service here is dockhub built-in, of course, there are other things such as ETCD, Consul, etc.) )
Docker run--RM swarm create
rw4d3ac32aa6a86b341e3asd69e2cd0b
After executing the above command, a token is generated. Start Swarn Manager
Docker run-ti-d-P 2376:2375 \
--restart=always \
--name shipyard-swarm-manager \
docker.io/swarm:latest \
Manage--host tcp://0.0.0.0:2375 \
Swarn Manager only needs to start one, so you can choose a Docker node to start up, and here I start on my host 10.0.11.150. start swarm Agent
Start the Swarm agent and add the current Docker node to the cluster, and the Swarm agent needs to be started on each Docker node that is to be added to the cluster.
Docker run-ti-d \
--restart=always \
--name shipyard-swarm-agent \
docker.io/swarm:latest \
Join-- Addr [Docker node ip]:2375 \
token://rw4d3ac32aa6a86b341e3asd69e2cd0b
Note: The [Docker node IP] entry in the above command needs to be replaced with the real IP of the Docker node to be added to the cluster. View Docker node conditions
You can use commands to view Docker node conditions (which can be performed on any Docker node):
Docker run--RM swarm list token://rw4d3ac32aa6a86b341e3asd69e2cd0b
View Docker cluster details
You can use the commands to view the details of the Docker cluster (which can be performed on any Docker node, IP address is the IP of the Swarm master host):
Docker-h 10.0.11.150:2376 Info