Getting started with Docker swarm
The worst way to install swarm is to use the image on the Docker website.
root@syx-vb:~# DAO Pull Swarm
use the following command to see if the Swarm is installed successfully:
root@syx-vb:~# Docker run--rm swarm-v
swarm version 1.2.2 (34E3DA3)
Use
before using swarm to manage the cluster, you need to change the Docker daemon of all nodes in the cluster to 0.0.0.0:2375. There are two ways:
(1). When you start the Docker daemon, specify:
sudo docker-h 0.0.0.0:2375&
(2). Directly modify the Docker configuration file (/etc/default/docker on Ubuntu), add the following code at the end of the file:
docker_opts= "-H 0.0.0.0:2375-h unix:///var/run/docker.sock"
It is important to note that it must be done on all nodes that want to be managed by swarm. To restart Docker after modification:
Service Docker restart
Docker Cluster management requires the use of the service discovery (Discovery service backend) feature , Swarm supports several ways: Dockerhub provides service discovery capabilities, local files, Etcd,counsel, Zookeeper and IP lists.
This experiment consists of three machines with IP addresses:
host1:192.168.3.144;
host2:192.168.3.172;
host3:114.215.97.162;
Why is the IP address of the three machines a little bit different? Because the landlord wanted to prove that even three away from the machine can also use swarm management.
Use these three machines to form a cluster, where 172 of these machines act as swarm manage management nodes.
first step. Create a Cluster token
Performed on any of the three machines above:
root@syx-vb:~# sudo docker run--rm swarm create
4d53d13612f3a655449eb40596a1a1ec
You can see the return of an ID, which is the only one in the world, to identify the cluster to be managed, there may be a timeout error, you can see if your machine can surf the internet, because the landlord's virtual machine in the acquisition of frequent errors, However, the use of this command after replacing the server with Alibaba Cloud does not produce a single error.
Remember this global unique ID. Because each time you return a different ID.
The second step is to add the host you want to the cluster:
The simple step is to execute the following command on each host that you need to join the cluster:
sudo docker run-rm swarm join--addr=ip_address:2375 TOKEN://4D53D13612F3A655449EB40596A1A1EC
the ip_address here is replaced by the IP of your own machine.
The case is as follows, in 172 the command executed by this machine is as follows:
root@syx-vb:~# Docker run--rm swarm join--addr=192.168.3.172:2375 TOKEN://4D53D13612F3A655449EB40596A1A1EC
The results returned are as follows:
Time= "2016-05-18t11:33:03z" Level=info msg= "registering on the discovery service every 1m0s ..." addr= " 192.168.3.172:2375 "discovery=" Token://4d53d13612f3a655449eb40596a1a1ec "
This command does not end automatically, you need to press CTRL + C to force the end.
The commands for the remaining two machines are similar.
The final step is to use 172 this host as the management node, you need to execute the Swarm manage command on this host 172:
root@syx-vb:~# Docker run-d-P 2376:2375 Swarm manage Token://4d53d13612f3a655449eb40596a1a1ec
The returned result is the ID of the swarm container that has been started, when the entire cluster has started up.
ccb604d3d393e22bb02b4b9d4a2aa8734b95e3ad8a32626fdda2f7686c6bf128
This time you run:
root@syx-vb:~# Docker PS
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ccb604d3d393 swarm "/swarm Manage token:" About a minute ago up about a minute 0.0.0.0:2376- >2375/tcp Naughty_boyd
Can see that the swarm has been successfully started. There are a few things to note when executing the swarm command:
1. This command needs to be performed on a machine that acts as a swarm manager (172 of this machine in this case).
2.swarm is to be executed in the form of daemon.
3. The mapped port can be anything other than 2375, but it cannot be 2375.
Test it:
The most critical moment is here, at this time you can use the Swarm List command on any cluster machine to see the nodes in the cluster, such as the one I see in this cluster on the 144 machine:
root@syx-vb:~# Docker run--RM swarm list token://4d53d13612f3a655449eb40596a1a1ec
114.215.97.162:2375
192.168.3.144:2375
192.168.3.172:2375
here the landlord found a problem, is that your machine can only join a cluster, the landlord began to use swarm to create a cluster, no problem, landlord and create a new cluster of music, found that the front of no problem, is in the test when the content is not displayed.
The second problem is, in the test when the landlord wants to check the information of other machines, such as the landlord now on the 172 machine to execute the following command:
root@syx-vb:~# docker-h 192.168.3.144:2376 Info
The information returned is as follows:
Cannot connect to the Docker daemon. Is the Docker daemon running on this host?
What this means, the landlord has not figured out, if there is great God know how to solve, hope to tell younger brother, grateful.
There is a problem, the younger brother in the open 2375 port monitoring, the error occurred:
root@syx-vb:~# docker-h tcp://0.0.0.0:2375-d Warning: '-d ' is deprecated, it'll be removed soon.
See usage.
WARN[0000] Please use ' Docker daemon ' instead. WARN[0000]/!\ don ' t BIND on any IP ADDRESS without setting-tlsverify IF you DON ' t KNOW what you ' RE DOING/!\ info[0000] API Listen on [::]:2375 info[0000] [graphdriver] using prior storage driver "Aufs" info[0000] Firewa LLD Running:false info[0001] Default Bridge (DOCKER0) is assigned with an IP address 172.17.0.1/16.
Daemon option--bip can be used to set a preferred IP address warn[0001] Your kernel does not the support swap memory limit.
INFO[0001] Loading Containers:start. .......................................... WARN[0001] Failed to allocate and map port 5000-5000:error starting userland proxy:listen TCP 0.0.0.0:5000:bind:addres s already in use erro[0001] Error locating sandbox ID 8962a74abfb1fdcc00518500b659cab4bdcde4b8aaef6ae263f092f7587f2b83: SanDbox 8962a74abfb1fdcc00518500b659cab4bdcde4b8aaef6ae263f092f7587f2b83 not found warn[0001] failed to cleanup IPC mounts : Failed to Umount/var/lib/docker/containers/29c3e5ab6ac7544aead75c13bb6f183a64b502e28d228d46c8bb1ff945ff7c3a/shm : Invalid argument failed to umount/var/lib/docker/containers/ 29c3e5ab6ac7544aead75c13bb6f183a64b502e28d228d46c8bb1ff945ff7c3a/mqueue:invalid argument ERRO[0001] Failed to start Container 29c3e5ab6ac7544aead75c13bb6f183a64b502e28d228d46c8bb1ff945ff7c3a:failed to create endpoint registry on Network Bridge:error starting userland proxy:listen TCP 0.0.0.0:5000:bind:address already in use info[0001] Loading
Containers:done. INFO[0001] Daemon has completed initialization info[0001] Docker Daemon commit=a 34a1d5 execdriver=native-0.2 graphdriver=aufs version=1.9.1 ^cinfo[0079] processing signal ' interrupt '