‫Okay,
‫so what I'm going to do is, I'm going to walk through each one of these services based on this architecture,
‫and I'm going to create this app on the fly. I'm actually going to type the commands in here in the readme,
‫because that seems like a logical place for me to do it. And then I'll cut and paste them into my
‫node.
‫If you remember, I have a 3-node Swarm over here. If I do a docker node ls,
‫you’ll see that I have three nodes here. They're all manager nodes.
‫I have no containers running, and no services, obviously. First thing, I know up at the top,
‫it talks about I need networks, and I need a volume.
‫So, probably can get the networks out of the way and I can probably wing that. I can type docker
‫network create d overlay. Remember that the overlay network is the only kind of network we can use
‫in a Swarm because overlay allows us to span across nodes, as if they're all on the local network.
‫And then I want to call it backend.
‫And then, I want to do the same exact thing, only call it frontend.
‫Now, there's nothing inherently special about these two networks.
‫We're just going to segment our different services into one or the other to help act like a little firewall
‫that gives separation for protection.
‫On this vote one,
‫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
‫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
‫frontend. I need two replicas.
‫So, replica two. And then, I might as well just copy and paste this name.
‫Now, I'm going to go ahead and create all of these before I actually deploy them.
‫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,
‫it's going to be called redis.
‫You don't have to worry about publishing any ports on that.
‫It's going to be on the frontend network.
‫I want two replicas, and then, I’m going to call it redis three two is the image.
‫Down here, docker service create name worker, is going to be on two networks. I’ve got to do network
‫frontend and...whoops.
‫I’m typing what I'm saying...let’s see, network backend, and then only one replica.
‫…
‫Because one replica is default,
‫I don't actually have to specify replica and I don't specify any ports.
‫I think, that's all I need there. I just need to copy over the image.
‫Okay, docker service create name db network backend.
‫See, one replica.
‫Oh, I need to do this volume.
‫Here's the thing about the volume. The -v command is not compatible with docker services. Because, for various
‫reasons, services are going to be more complex than maybe your typical docker run.
‫And there were problems and limitations with the -v back in the day.
‫So, Docker has learned from that and improved the format. But it happens to be a little bit more verbose
‫and maybe a little bit more difficult to remember the format starting out.
‫It also happens to be not well documented yet in the Docker Documentation because it's less than
‫a year old as a command. So, we're going to just copy and paste this. If it doesn't make sense to you,
‫basically, it's this list of values that are all a part of a single mount command and the minimums are
‫a type, a source, and a target.
‫There's also other things you can add on, but these are the only three we need in this scenario.
‫And you can see my source is just a named volume because I don't have any slashes in it.
‫And if we had slashes it would have been a bind mount and we would have to had specified a different
‫type.
‫So down here, --mount type volume, source db data, target.
‫I think that's correct.
‫And then you can just, postgres 9.4.
‫And then the last one is the result app.
‫So, docker service create name result network backend.
‫Publish the port. We’re going to use 5001 to port 80 in the container.
‫I only can run one of them. By the way, the only reason we're running one of these is actually a little
‫known issue on this app, is that this is actually using WebSockets, and WebSockets are something that require
‫a persistent connection.
‫...
‫So, in the routing mesh, doesn't really do WebSockets well yet because it's going to keep switching you
‫back and forth between containers and that WebSocket needs to be to a specific container persistently.
‫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
‫probably in a later version they'll update it and fix it so that we have a proxy.
‫That way it can be redundant
‫and sure you're getting to the right container. We’re going to
‫copy and paste this to the end. I just realized I'm missing the last value on these.
‫Okay, and then I’m going to start at the top and just copy and paste. It's already created the networks.
‫Yes, this needs to be replicas. Let me update that over here.
‫Replicas. Okay, we’re going to create the redis. There we go.
‫All right, created that one. Now, you'll notice, by the way, I get back a service ID but it doesn't mean that
‫the service is actually deployed correctly.
‫We'll look at that in a minute.
‫Let me get the rest of these in there.
‫All right.
‫Now that we have that, we should be able to do the rest of our commands over here. So, docker service ls shows
‫us all five of them. And you'll notice that the replica numbers match.
‫That's a good sign.
‫That means that one has been created successfully.
‫And if I wanted to dig in deeper, I could do a docker service ps on each one.
‫All right, so that one's been running 28 seconds.
‫redis has been running a minute. db is running 53 seconds. vote.
‫worker.
‫And you'll see here in the worker, that we have a failed task that shut down, and then one that's running.
‫That's been running for 47 seconds.
‫Okay, so, I actually know why this happened, but you may not know, so maybe we would have to do a logs.
‫Now this is on node2.
‫An experimental feature that you can enable through an optional config in Docker, is actually to
‫do the new experimental feature, docker service logs. Which actually pulls the logs from many different nodes.
‫Hopefully, it'll be released in the next version of Docker later this year.
‫But for now, it's experimental. So I had to enable it inside of the etc docker daemon log, or daemon.
‫json file. And, just so you know, this is how you would enable an experimental.
‫That's not a part of this.
‫That's just something I did, just so that I could show this off real quick.
‫You might be seeing this error and you’re thinking, I don't know why is that happening?
‫We can look at that log. So, we can do a docker service log worker...oops...logs worker.
‫And this is on, this particular, let’s see, these are two different...
‫You can see here this is one, and then the number changes. Actually, yeah.
‫This is all one right here.
‫It says no such device or address.
‫So, what this basically means is, I created a service that was looking for a DNS record that didn't
‫exist because I hadn't created the other service yet. And it did the thing it's supposed to do in
‫“Dockerland”, which is when it has an error like that, the app should crash because Docker can actually
‫restart and redeploy things properly until the apps don't crash. And as soon as I get all my services
‫launched, everything stopped crashing and everything now works.
‫And we can tell that by just going back and looking at the ps worker. We see that it's been running
‫successfully for three minutes.
‫So let's take a look at our app.
‫If I just pull up the IP address, I should get the dogs and cats. I'm going to vote cats.
‫And then if I go to that same IP on port 5001, I should see the results app. That's
‫the app.
‫We now know that it's working because the only way that this can change is if this goes all the way
‫through when it gets caught up by the redis, and then processed by the worker, and then put in the database.
‫So we know that each of our app services are able to talk to each other. And we can look at the logs
‫if we wanted to.
‫But, that's the demo.