1 00:00:04,680 --> 00:00:05,050 ‫Okay, 2 00:00:05,070 --> 00:00:10,650 ‫so what I'm going to do is, I'm going to walk through each one of these services based on this architecture, 3 00:00:10,710 --> 00:00:17,370 ‫and I'm going to create this app on the fly. I'm actually going to type the commands in here in the readme, 4 00:00:17,370 --> 00:00:22,230 ‫because that seems like a logical place for me to do it. And then I'll cut and paste them into my 5 00:00:22,230 --> 00:00:22,920 ‫node. 6 00:00:22,950 --> 00:00:27,340 ‫If you remember, I have a 3-node Swarm over here. If I do a docker node ls, 7 00:00:27,360 --> 00:00:32,270 ‫you’ll see that I have three nodes here. They're all manager nodes. 8 00:00:32,370 --> 00:00:40,470 ‫I have no containers running, and no services, obviously. First thing, I know up at the top, 9 00:00:40,470 --> 00:00:46,620 ‫it talks about I need networks, and I need a volume. 10 00:00:46,780 --> 00:00:52,870 ‫So, probably can get the networks out of the way and I can probably wing that. I can type docker 11 00:00:53,380 --> 00:01:01,960 ‫network create d overlay. Remember that the overlay network is the only kind of network we can use 12 00:01:01,960 --> 00:01:08,920 ‫in a Swarm because overlay allows us to span across nodes, as if they're all on the local network. 13 00:01:09,800 --> 00:01:12,710 ‫And then I want to call it backend. 14 00:01:13,770 --> 00:01:18,510 ‫And then, I want to do the same exact thing, only call it frontend. 15 00:01:19,280 --> 00:01:22,890 ‫Now, there's nothing inherently special about these two networks. 16 00:01:22,970 --> 00:01:29,060 ‫We're just going to segment our different services into one or the other to help act like a little firewall 17 00:01:29,060 --> 00:01:32,080 ‫that gives separation for protection. 18 00:01:33,140 --> 00:01:34,170 ‫On this vote one, 19 00:01:34,210 --> 00:01:45,100 ‫I know I need to do a docker service create, and I’ve got to name it, so I might as well put name vote. And then 20 00:01:45,100 --> 00:01:53,380 ‫I’ve got to publish the port 80 to 80 in the container, and it's got to be on a specific network. So, network 21 00:01:55,420 --> 00:01:59,140 ‫frontend. I need two replicas. 22 00:01:59,200 --> 00:02:13,030 ‫So, replica two. And then, I might as well just copy and paste this name. 23 00:02:13,290 --> 00:02:18,970 ‫Now, I'm going to go ahead and create all of these before I actually deploy them. 24 00:02:19,100 --> 00:02:27,100 ‫I’m going to actually copy this one down here. This one is going to be called...it’s not going to be called vote, 25 00:02:27,100 --> 00:02:29,360 ‫it's going to be called redis. 26 00:02:29,470 --> 00:02:31,890 ‫You don't have to worry about publishing any ports on that. 27 00:02:31,880 --> 00:02:33,520 ‫It's going to be on the frontend network. 28 00:02:33,520 --> 00:02:42,740 ‫I want two replicas, and then, I’m going to call it redis three two is the image. 29 00:02:46,410 --> 00:02:55,380 ‫Down here, docker service create name worker, is going to be on two networks. I’ve got to do network 30 00:02:55,380 --> 00:02:59,060 ‫frontend and...whoops. 31 00:02:59,370 --> 00:03:07,370 ‫I’m typing what I'm saying...let’s see, network backend, and then only one replica. 32 00:03:07,380 --> 00:03:07,630 ‫… 33 00:03:07,640 --> 00:03:08,980 ‫Because one replica is default, 34 00:03:09,000 --> 00:03:12,210 ‫I don't actually have to specify replica and I don't specify any ports. 35 00:03:12,210 --> 00:03:18,450 ‫I think, that's all I need there. I just need to copy over the image. 36 00:03:21,290 --> 00:03:29,530 ‫Okay, docker service create name db network backend. 37 00:03:32,500 --> 00:03:34,050 ‫See, one replica. 38 00:03:34,510 --> 00:03:36,340 ‫Oh, I need to do this volume. 39 00:03:36,400 --> 00:03:44,050 ‫Here's the thing about the volume. The -v command is not compatible with docker services. Because, for various 40 00:03:44,050 --> 00:03:48,100 ‫reasons, services are going to be more complex than maybe your typical docker run. 41 00:03:48,100 --> 00:03:52,650 ‫And there were problems and limitations with the -v back in the day. 42 00:03:52,650 --> 00:03:59,040 ‫So, Docker has learned from that and improved the format. But it happens to be a little bit more verbose 43 00:04:00,750 --> 00:04:05,980 ‫and maybe a little bit more difficult to remember the format starting out. 44 00:04:06,060 --> 00:04:11,790 ‫It also happens to be not well documented yet in the Docker Documentation because it's less than 45 00:04:11,790 --> 00:04:18,640 ‫a year old as a command. So, we're going to just copy and paste this. If it doesn't make sense to you, 46 00:04:18,640 --> 00:04:26,160 ‫basically, it's this list of values that are all a part of a single mount command and the minimums are 47 00:04:26,160 --> 00:04:28,950 ‫a type, a source, and a target. 48 00:04:28,950 --> 00:04:34,580 ‫There's also other things you can add on, but these are the only three we need in this scenario. 49 00:04:34,920 --> 00:04:39,810 ‫And you can see my source is just a named volume because I don't have any slashes in it. 50 00:04:40,110 --> 00:04:44,430 ‫And if we had slashes it would have been a bind mount and we would have to had specified a different 51 00:04:44,430 --> 00:04:45,000 ‫type. 52 00:04:45,000 --> 00:04:52,560 ‫So down here, --mount type volume, source db data, target. 53 00:04:52,590 --> 00:04:53,660 ‫I think that's correct. 54 00:04:53,670 --> 00:04:59,900 ‫And then you can just, postgres 9.4. 55 00:05:02,880 --> 00:05:04,740 ‫And then the last one is the result app. 56 00:05:04,750 --> 00:05:13,710 ‫So, docker service create name result network backend. 57 00:05:16,930 --> 00:05:22,180 ‫Publish the port. We’re going to use 5001 to port 80 in the container. 58 00:05:24,790 --> 00:05:30,460 ‫I only can run one of them. By the way, the only reason we're running one of these is actually a little 59 00:05:30,460 --> 00:05:37,630 ‫known issue on this app, is that this is actually using WebSockets, and WebSockets are something that require 60 00:05:37,630 --> 00:05:39,120 ‫a persistent connection. 61 00:05:39,160 --> 00:05:39,540 ‫... 62 00:05:39,550 --> 00:05:44,680 ‫So, in the routing mesh, doesn't really do WebSockets well yet because it's going to keep switching you 63 00:05:44,740 --> 00:05:50,110 ‫back and forth between containers and that WebSocket needs to be to a specific container persistently. 64 00:05:50,110 --> 00:05:59,140 ‫So, with this app what we should have really, is a proxy in front of it but it's not in this app yet so 65 00:05:59,170 --> 00:06:03,430 ‫probably in a later version they'll update it and fix it so that we have a proxy. 66 00:06:03,610 --> 00:06:05,320 ‫That way it can be redundant 67 00:06:05,320 --> 00:06:09,180 ‫and sure you're getting to the right container. We’re going to 68 00:06:09,200 --> 00:06:18,260 ‫copy and paste this to the end. I just realized I'm missing the last value on these. 69 00:06:21,860 --> 00:06:28,580 ‫Okay, and then I’m going to start at the top and just copy and paste. It's already created the networks. 70 00:06:31,890 --> 00:06:36,970 ‫Yes, this needs to be replicas. Let me update that over here. 71 00:06:37,020 --> 00:06:46,180 ‫Replicas. Okay, we’re going to create the redis. There we go. 72 00:06:49,340 --> 00:06:56,880 ‫All right, created that one. Now, you'll notice, by the way, I get back a service ID but it doesn't mean that 73 00:06:56,880 --> 00:06:59,490 ‫the service is actually deployed correctly. 74 00:06:59,520 --> 00:07:00,820 ‫We'll look at that in a minute. 75 00:07:02,400 --> 00:07:03,950 ‫Let me get the rest of these in there. 76 00:07:12,700 --> 00:07:13,270 ‫All right. 77 00:07:13,480 --> 00:07:22,150 ‫Now that we have that, we should be able to do the rest of our commands over here. So, docker service ls shows 78 00:07:22,150 --> 00:07:26,040 ‫us all five of them. And you'll notice that the replica numbers match. 79 00:07:26,050 --> 00:07:27,420 ‫That's a good sign. 80 00:07:27,550 --> 00:07:31,350 ‫That means that one has been created successfully. 81 00:07:31,500 --> 00:07:38,820 ‫And if I wanted to dig in deeper, I could do a docker service ps on each one. 82 00:07:38,820 --> 00:07:41,890 ‫All right, so that one's been running 28 seconds. 83 00:07:45,090 --> 00:07:52,860 ‫redis has been running a minute. db is running 53 seconds. vote. 84 00:07:54,830 --> 00:07:55,580 ‫worker. 85 00:08:00,320 --> 00:08:10,220 ‫And you'll see here in the worker, that we have a failed task that shut down, and then one that's running. 86 00:08:10,290 --> 00:08:13,470 ‫That's been running for 47 seconds. 87 00:08:13,490 --> 00:08:21,220 ‫Okay, so, I actually know why this happened, but you may not know, so maybe we would have to do a logs. 88 00:08:21,230 --> 00:08:22,760 ‫Now this is on node2. 89 00:08:26,010 --> 00:08:32,540 ‫An experimental feature that you can enable through an optional config in Docker, is actually to 90 00:08:32,540 --> 00:08:39,700 ‫do the new experimental feature, docker service logs. Which actually pulls the logs from many different nodes. 91 00:08:39,890 --> 00:08:44,050 ‫Hopefully, it'll be released in the next version of Docker later this year. 92 00:08:44,070 --> 00:08:53,030 ‫But for now, it's experimental. So I had to enable it inside of the etc docker daemon log, or daemon. 93 00:08:53,360 --> 00:08:56,890 ‫json file. And, just so you know, this is how you would enable an experimental. 94 00:08:56,900 --> 00:08:57,830 ‫That's not a part of this. 95 00:08:57,830 --> 00:09:00,680 ‫That's just something I did, just so that I could show this off real quick. 96 00:09:00,680 --> 00:09:05,280 ‫You might be seeing this error and you’re thinking, I don't know why is that happening? 97 00:09:05,390 --> 00:09:16,370 ‫We can look at that log. So, we can do a docker service log worker...oops...logs worker. 98 00:09:16,570 --> 00:09:21,090 ‫And this is on, this particular, let’s see, these are two different... 99 00:09:21,580 --> 00:09:27,960 ‫You can see here this is one, and then the number changes. Actually, yeah. 100 00:09:28,060 --> 00:09:30,610 ‫This is all one right here. 101 00:09:30,700 --> 00:09:33,400 ‫It says no such device or address. 102 00:09:33,400 --> 00:09:39,040 ‫So, what this basically means is, I created a service that was looking for a DNS record that didn't 103 00:09:39,040 --> 00:09:43,480 ‫exist because I hadn't created the other service yet. And it did the thing it's supposed to do in 104 00:09:43,480 --> 00:09:49,330 ‫“Dockerland”, which is when it has an error like that, the app should crash because Docker can actually 105 00:09:49,330 --> 00:09:54,940 ‫restart and redeploy things properly until the apps don't crash. And as soon as I get all my services 106 00:09:54,940 --> 00:09:58,900 ‫launched, everything stopped crashing and everything now works. 107 00:09:58,900 --> 00:10:04,120 ‫And we can tell that by just going back and looking at the ps worker. We see that it's been running 108 00:10:04,120 --> 00:10:05,950 ‫successfully for three minutes. 109 00:10:06,580 --> 00:10:10,420 ‫So let's take a look at our app. 110 00:10:10,760 --> 00:10:19,400 ‫If I just pull up the IP address, I should get the dogs and cats. I'm going to vote cats. 111 00:10:19,580 --> 00:10:26,190 ‫And then if I go to that same IP on port 5001, I should see the results app. That's 112 00:10:26,190 --> 00:10:26,680 ‫the app. 113 00:10:26,760 --> 00:10:31,140 ‫We now know that it's working because the only way that this can change is if this goes all the way 114 00:10:31,140 --> 00:10:35,590 ‫through when it gets caught up by the redis, and then processed by the worker, and then put in the database. 115 00:10:35,850 --> 00:10:41,090 ‫So we know that each of our app services are able to talk to each other. And we can look at the logs 116 00:10:41,100 --> 00:10:41,620 ‫if we wanted to. 117 00:10:41,640 --> 00:10:42,920 ‫But, that's the demo.