1 00:00:00,567 --> 00:00:03,034 Let's use Docker Swarm for the reason it is 2 00:00:03,034 --> 00:00:07,134 designed, which is to have multiple replicas of a 3 00:00:07,134 --> 00:00:11,067 container or to use services with multiple containers themselves. 4 00:00:11,934 --> 00:00:13,734 We'll create a service 5 00:00:13,734 --> 00:00:18,234 called web-server from latest nginx image and have 6 00:00:18,234 --> 00:00:21,567 3 replicas for it. We have also mentioned port 7 00:00:21,567 --> 00:00:24,167 mapping information with -p flag. 8 00:00:24,567 --> 00:00:28,467 Once we hit enter, you can see that our service has been 9 00:00:28,467 --> 00:00:31,767 divided into three tasks, and each task has been 10 00:00:31,767 --> 00:00:35,034 carried out individually. Once the tasks are 11 00:00:35,034 --> 00:00:38,267 complete, the service has been verified, and once 12 00:00:38,267 --> 00:00:41,034 the service creation is complete, we can list it 13 00:00:41,034 --> 00:00:44,634 using docker service ls command. First of all, we 14 00:00:44,634 --> 00:00:48,334 have service ID, then we have the NAME of service, 15 00:00:48,334 --> 00:00:52,234 which is same as we had provided with the command web-server. 16 00:00:52,534 --> 00:00:55,201 Then we have mode of service, it is 17 00:00:55,201 --> 00:00:58,401 replicated, which means the same image has been 18 00:00:58,401 --> 00:01:01,601 replicated more than once and multiple instances 19 00:01:01,601 --> 00:01:05,801 or multiple containers are created from the same image. 20 00:01:05,801 --> 00:01:08,767 We have three replicas in particular. 21 00:01:08,767 --> 00:01:13,134 The image, which has been used is the latest nginx, 22 00:01:13,134 --> 00:01:16,901 and we also have port mapping information for TCP. 23 00:01:17,067 --> 00:01:19,567 If we want to have a look at the containers 24 00:01:19,567 --> 00:01:22,001 running inside the service, the command is pretty 25 00:01:22,001 --> 00:01:25,567 simple. Just write docker service ps followed by 26 00:01:25,567 --> 00:01:28,134 the name of the service. Here we have three 27 00:01:28,134 --> 00:01:32,134 containers, and the naming convention is pretty simple. 28 00:01:32,467 --> 00:01:39,001 The names are web-server.1, web-server.2, and web-server.3. 29 00:01:39,001 --> 00:01:43,001 They are up and running for about the same time and all of 30 00:01:43,001 --> 00:01:46,134 them share the common nginx:latest image. 31 00:01:46,134 --> 00:01:50,967 Just like we had done with docker-compose, let's inspect our service. 32 00:01:51,201 --> 00:01:53,267 And as we go further, along 33 00:01:53,267 --> 00:01:56,034 with the generic information, we also get some 34 00:01:56,067 --> 00:01:58,301 additional information like the mode of the 35 00:01:58,301 --> 00:02:02,067 service, which is replicated, and details regarding 36 00:02:02,067 --> 00:02:05,134 all of the hosts, or all of the machines, where 37 00:02:05,134 --> 00:02:07,534 each and every container of the service is 38 00:02:07,534 --> 00:02:11,567 provisioned. Unlike docker service ps, if we 39 00:02:11,567 --> 00:02:15,167 regularly run docker ps -a command on any 40 00:02:15,167 --> 00:02:18,667 of the node, we will get to know that each of the 41 00:02:18,667 --> 00:02:21,534 node is only running one container. 42 00:02:21,534 --> 00:02:25,234 That is because, the service has been deployed across the 43 00:02:25,234 --> 00:02:29,467 cluster, which means that the load was divided evenly. 44 00:02:29,467 --> 00:02:32,234 Since we had 3 replicas, all of these 45 00:02:32,234 --> 00:02:35,601 containers were sheduled on an individual node, 46 00:02:35,967 --> 00:02:40,034 web-server.1 was scheduled on manager node, 47 00:02:40,034 --> 00:02:44,134 web-server.2 was scheduled on worker-1 node 48 00:02:44,134 --> 00:02:47,467 and web-server.3 was scheduled on worker 49 00:02:47,467 --> 00:02:50,601 worker to node just like a regular container, 50 00:02:50,601 --> 00:02:54,101 we can inspect this web-server.1 as well. 51 00:02:54,101 --> 00:02:58,167 Now, this means that all of these 3 nodes are 52 00:02:58,167 --> 00:03:01,934 running at least one instance of nginx web server. 53 00:03:01,934 --> 00:03:05,367 So all of them should be serving nginx default web page 54 00:03:05,367 --> 00:03:10,101 on their respective IP addresses on their port 8080. 55 00:03:10,234 --> 00:03:14,567 Let's go to browser and check this fact with our manager node. 56 00:03:15,934 --> 00:03:18,101 See that we are navigating 57 00:03:18,101 --> 00:03:24,067 to the IP of the manager which is 192.168.99.100, 58 00:03:24,434 --> 00:03:28,134 and we are mentioning the port 8080. 59 00:03:29,234 --> 00:03:34,034 It seems like a success. Now, let's do the same with 60 00:03:34,034 --> 00:03:37,267 worker-1 and worker-2. This means that the 61 00:03:37,267 --> 00:03:41,034 service is running successfully. And Docker Swarm 62 00:03:41,034 --> 00:03:45,267 is hosting nginx web server on all of these 3 nodes.