‫This is going to be the first lecture where we're actually going to use multiple hosts or nodes,
‫or instances, or whatever you want...multiple OS's. We're going to set up a 3-node swarm across
‫all three of those nodes.
‫We unfortunately can't do this part with the built-in Docker on your machine because that's only going to
‫provide us one OS. We need three Linux OS's to play with this next set of features.
‫The first option you're going to have is using play-with-docker.com.
‫It's absolutely the easiest way to get started.
‫It comes with Docker pre-installed. It takes you seconds to provision three different machines, and it requires
‫no investment on your end. But it does mean that every four hours it will wipe all the work you've done.
‫So if you think you're going to do the rest of this section over the course of days, then this may not
‫be the best option for you. But if you're going to focus for a few hours, you can definitely get through
‫most, if not all, of the multi node swarm stuff using Play With Docker in one sitting.
‫Another option you have is you can use docker-machine, which is not something we've talked about yet,
‫but it's a command line tool that actually gets installed with Docker for Windows and Docker for Mac.
‫You can download it for Linux, and it is basically an automation tool for provisioning virtual machines
‫locally, and on the Internet, and then automatically setting up Docker for you.
‫The default way that it works is with VirtualBox, which you can install free. But it does mean that if
‫you're going to run three virtual machines locally, each one of them probably needs a gig of RAM or so
‫to run through a lot of these examples. So you'll need a machine with a good amount of RAM in it. Another
‫option, and the one that I'm going to default to for a lot of these demos and walk throughs, is DigitalOcean.
‫I just recommend DigitalOcean just because they have the cheapest and easiest service to
‫get started, and they run everything on SSD so it's nice and fast. You can actually use this in a
‫very, very similar set up to what production would be because you're using three actual virtual machines,
‫in the cloud, and it takes about a minute to launch each virtual machine.
‫If you're thinking that that might be an option, you can use my referral code and the references to
‫this section to get your first $10 free.
‫If you're only going to take a few days to get through this swarm stuff, you can provision three, $10 a
‫month nodes and have them up for days or a week.
‫And that might fit within the $10 budget so technically wouldn't cost you anything.
‫And then lastly, there are so many ways to get Docker installed, and that's really all you need is three
‫machines with Docker installed on them. You can use Docker Machine.
‫It has built in drivers that allow you to use it to provision Amazon instances, or Azure instances, or
‫DigitalOcean Droplets, or Google Compute nodes or any place you can get a Linux virtual machine, you
‫can actually just install Docker with an automated script from get.docker.com.
‫Frankly, I prefer the get.docker.com version only because Docker Machine may save you a few steps,
‫especially for locations like Amazon and Azure that require you to provision a lot of different things
‫before you can get to just provisioning a virtual machine. But you're probably not going to be using
‫Docker Machine in production.
‫It is a tool to simply automate dev and test environments. It was never really designed to set up all
‫of the production settings you might need for a multi-node swarm.
‫There's nothing inherently wrong with it, but typically get.docker.com works on all the major
‫Linux distributions and doesn't take any longer than actually using Docker Machine itself.
‫I'm going to give you a really quick example of just getting any of these scenarios to the point
‫where Docker is installed. Then they all will be very similar in the way we actually create the
‫swarm and do our services.
‫So don't think that you have to do it the way I do it.
‫Really we're just trying to get Docker info to actually bring back information, and then just to make
‫sure that the three nodes have networking access to each other and they're on a well connected network.
‫So ideally they should be in the same network.
‫If you were going to use Play With Docker, you actually just go to play-with-docker.com and check
‫on the box for I'm not a robot.
‫And if it gives you the CAPTCHA screen, just follow along.
‫All right. You'll see that it's counting down by four hours.
‫But if I just click the creating instance, and then I click it two more times, it'll create three virtual
‫environments very quickly.
‫As a side note, this is actually using Docker in Docker, which is a pretty neat technology where we're
‫actually running Docker inside a Docker container.
‫But in this set up with Play With Docker, which was created by other Docker captains and the Docker team,
‫it's really hard to tell a difference.
‫If I go to node1, I can already see that Docker info gives me the latest version. And if I even tried
‫to ping node2, it actually recognizes friendly names, so it will make it easier to communicate back and
‫forth between them.
‫So if this is something you want to try, it's a great and easy way on either low-powered machines
‫or if you just don't want to take the time to set up an environment for the next four hours.
‫Option two is to use docker-machine. If you have it installed, it should be at least version 10
‫if not newer.
‫You'll know if it's installed because you'll type the docker-machine command from your command line and
‫it'll either work or it won't.
‫If you need to download it for your particular Linux OS, then you can hop over to the Docker Documentation,
‫which will actually give you a quick curl line to download it.
‫If you're using the ToolBox on Windows 7 and 8, or Docker for Windows on Windows 10, or Docker for
‫Mac on Mac OS, it's already going to be up to date on those OS's for you.
‫If you want to use the VirtualBox option, which is the default, you just need to jump over to
‫virtualbox.org and download the latest version for your OS. And you don't even have to do anything with
‫VirtualBox.
‫It just needs to be installed. And then from your command line, you can just type docker-machine create
‫node1, and this will actually run through creating a virtual machine with BusyBox, which is a very
‫lightweight Linux distribution.
‫This will actually run through creating a very lightweight Linux machine, and you'll just repeat those
‫two commands for node2 and 3.
‫If you need more information on a Docker Machine, you can actually look at my reference section
‫for tutorial links.
‫Once your machines are created, you really have two options for how you can access those machines.
‫You can either use docker-machine ssh, and then the name of the node you created and that'll hop you right
‫into that machine.
‫Or you can use the environment command.
‫So the command docker-machine env, and then the name of the machine you want, will give you some output,
‫and you can either cut and paste these options to your command line or you can copy and paste the bottom
‫option, and that will actually create the environment variable so that when I run my docker command,
‫because again, the Docker CLI just needs to know what Docker host to talk to. And by default, it's talking
‫to your local machine.
‫But that just reprogrammed it to talk to the Docker Machine
‫node1.
‫If I do docker info, you'll see that its name is node1 because that's the one I'm actually now operating
‫on.
‫For the last example, I'm going to use DigitalOcean, which I have created an account on.
‫Here, they call servers Droplets. I recommend if you don't have a specific reason to run another
‫OS, to start with Ubuntu 16.04 because that tends to be the first Linux distribution to support the
‫newer Docker features.
‫So that's the default there.
‫Then I would recommend for the remainder of this course for us to use the $10 a month server. You
‫might be able to get away with the $5 a month server, but it might get a little bit slow during some of
‫the later demos when we do monitoring and logging containers on top of our applications.
‫Then you can pick the data center closest to you. Then the only other option is to add an SSH key.
‫If you're not familiar with how to create your own SSH key locally and then upload the public into
‫DigitalOcean,
‫there's a great tutorial that they have for it that you can find in the resources of this section.
‫Down at the bottom I'm going to create three machines, and I'm going to call them node1, 2 and 3.
‫Then I need to wait probably about 60 seconds and they'll be ready for me.
‫You could just use the IP addresses here...jump on these machines.
‫Clicking the copy button and then ssh root @ the IP address.
‫And if your SSH key is properly set up on your machine, then it'll automatically log in with that
‫key.
‫But in the resources section, I've given you an example of how to set up a .ssh config file that will
‫allow you to have these three nodes in a config so you can just simply call them node1, node2,
‫node3, instead of having to remember their IP addresses, in case you're going to be doing this over multiple
‫days. That's really an easy way to get in and out of these servers.
‫If you've used Docker Machine, or if you used Play With Docker, then Docker is already installed
‫and you're getting ready to create your swarm.
‫But if you use DigitalOcean, or you roll your own VMs, then you need to get Docker installed.
‫The easiest way to do that, that I like to use, is to use the script over at get.docker.com.
‫You can see examples up here of how to use this script to get the current production release of
‫Docker on your machine.
‫Now, all three of my servers have the latest version of Docker installed and we're ready to set
‫up our swarm.
‫Again, all that's required is that these three nodes have solid networking to each other and specific
‫ports open.
‫If you're curious about the ports of swarm, look in the resources of this section where I actually
‫have a link to my own list of the firewall ports necessary for Swarm to work.
‫If you remember before, we did docker swarm init. Now, in this case, which is pretty common in cloud
‫servers, it wants us to specify an IP address to advertise the Swarm service on.
‫You want to use an IP address that is accessible from the other servers.
‫In this case, I'm going to use the public IP address for my DigitalOcean
‫host.
‫And there we go.
‫So far, this is just like on our local machine.
‫This time, though, I'm going to copy the swarm join command and go over to node2 and add it in.
‫And there we go.
‫This node is now a part of the swarm.
‫So we go back to node1, docker node ls, and now we have two.
‫You'll notice the second node is only a worker. Because as it says, if we wanted it to be a manager,
‫we should have gotten this manager token. But no worries. We can actually update this worker to promote
‫it to being a manager.
‫But if we're over on node2, notice that I can't use Swarm commands. Because workers aren't really privileged.
‫They don't have access to control the swarm.
‫So they're not going to be able to use any of the Swarm commands that we're used to using on the managers.
‫Back on node1 and the manager, I'm going to do a docker node update...
‫What I was doing there was hitting Tab for tab completion, which is always a fantastic feature in
‫Docker, especially with so many features. It was walking me through each step of how to use that update
‫command.
‫Now I've got this final update finished and it has changed node2.
‫Now if I do my docker node ls, you'll see that now it's considered reachable.
‫But the original node is still the leader. By the way, the little asterisk? That just means that's the
‫node you're currently talking to.
‫For node3, let's add it as a manager by default.
‫We need to go back to our original command of docker swarm, and then we need to get the join-token
‫manager.
‫You can get these tokens at any time.
‫You don't have to write them down or save them.
‫They're part of the swarm configuration and stored encrypted on disk, so don't worry about that.
‫You can also change these in case they possibly get exposed or you maybe get a server that might have
‫had a vulnerability on it, and you want to make sure that no nodes can join the swarm from the old key,
‫you can actually rotate these keys.
‫I'm going to copy this, paste it into node3.
‫And there we go. Back on node1.
‫If I do a docker node ls again, you'll see I've got three nodes. And they all have a manager status indicating
‫that they are managers.
‫So now we have a 3-node, redundant swarm, with three managers. Let's just do the same thing
‫we did earlier, docker service create alpine
‫ping 8.8.8.8
‫Only this time,
‫let's give it three replicas.
‫And then do a docker service
‫ls, and we'll see
‫we've got three of three already running.
‫If I did a docker node ps, I can actually see my local node is actually running this task or container.
‫I can actually specify the node, node2, and it'll give me just the containers running on node2.
‫If I wanted to get a full list, I could do a docker service ps, and then sleepy brown is the name that
‫it gave our service. And you'll see here..let me expand the screen a little bit.
‫You can see here that it's listing all three of our tasks.
‫Once you've got this swarm created, you normally don't need to be typing commands into all the different
‫nodes. You can really operate the whole swarm, for most things, from node1.
‫So we'll be doing a lot of our work from node1 in future lectures, but for now, pat yourself on the back
‫because you have a fully operational swarm cluster.