‫Now what about Docker Registry in a swarm?
‫It's not actually much different.
‫The nice thing is that we don't have to run a docker run command, we can actually use a docker service
‫command like we're used to or a stack file like we've talked about in a previous section. It's going
‫to work the same way as we did on the local host because we can actually just tell the swarm to talk
‫to itself for the registry.
‫So will use the same 127 address and we don't have to enable the insecure registry because that's already
‫allowed by the Docker Engine. The Routing Mesh basically allows all the nodes to talk to the registry
‫as if it's local,
‫right, because that's kind of the magic of the Routing Mesh.
‫I just want to remind you that this is a persistent data container.
‫It does store data that needs to last over time.
‫So you will have to deal in a real world production kind of scenario. You're going to have to deal with
‫a volume driver and how to deal, and basically make a decision around how you're going to store the
‫data.
‫But we won't do that here.
‫For this example with Swarm, I'm actually going to change it up a little bit and not use the three node cluster
‫that I had used in a previous section.
‫We're going to actually use Play With Docker this time. If you just go to play-with-docker.com,
‫we're going to actually prove that we're not a robot and then it's going to ask me some random
‫questions, it might ask you, it might not.
‫Then we're in.
‫Recently, the Play With Docker enabled a new feature that makes it even easier for us to set up a
‫test form and that's under the wrench object.
‫I guess that's a wrench. You see that there's options here that are basically templates for setting
‫up a swarm so instead of showing you this one set up like we've already done, I'm just going to set up
‫five managers, no workers, give it a second so it'll set all these up. Basically what we're going to
‫start with is a five node swarm. We're just going to run a registry real quick to show how it's pretty
‫much the same thing as before.
‫All right. Now I have five manager nodes and if I did docker node ls, You can just see that I have five
‫of them.
‫So yay. We have a swarm. Let's actually just run the registry but this time we're going to use the
‫service create
‫and call it registry.
‫We're going to publish it again like last time, port 5000,
‫and we're going to, the images registry.
‫There you go.
‫We can do a docker service ps registry and it says it's running. In Play With Docker,
‫we get this nice little button that shows up whenever we publish a web application.
‫It actually exposes the port and gives a nice little friendly URL that we can test that web app or
‫web endpoint.
‫But you know with Registry, at the root of it,
‫it is nothing, there's nothing that is returned other than a HTTP 200.
‫What we can do though is with any registry we can actually go and look at the catalog and that'll
‫return a simple JSON array.
‫You'll notice its repository is empty.
‫We could have done this in the previous lecture with it locally but let's just play with a little
‫bit here since we're in this easy solution with Play With Docker.
‫Let me do the same thing when I do a docker pull as before of the hello world. I'm now going
‫to do the tag remember again, so we're going to say tag hello world and then I'm going to rename it or
‫re-tag to a new repository 127.0.0.1 5000,
‫I'm going to do a docker push.
‫Let me zoom this in so it might be a little easier for us to see.
‫docker push.
‫Then we're going to do the 127.0.0.1
‫OK. Now it pushed that up to our repository. The way we can actually check, really quick, is
‫if you go to this other tab and I'll refresh, you'll notice that repositories now shows the name of the repo that is available.
‫As we add more to it this would actually expand the array and we would see all of them there.
‫At this point, I could just do as before, run that image, it would work just like we expected and scale
‫it up. To just prove that point,
‫I can do a docker pull nginx.
‫We can run a simple nginx web server,
‫docker tag nginx,
‫and then docker push,
‫push that back up to our registry.
‫Then you'll see here, that I have two now. I have two repositories there. Then
‫if I did a docker service create,
‫just like we do normally,
‫right,
‫we're going to do the nginx 80 80,
‫but this time I'm going to specify the image like so.
‫We're telling it we don't want to use the Docker Hub image,
‫right,
‫to start the service and we want to use this.
‫Now we're going to add in a couple of options.
‫I'm going to actually do replicas 5, so that one nginx will start on each node, and then we're
‫going to do a new option that started showing up in the 17.04 I believe, detach equals false and this will
‫allow us to actually see the command running in real time.
‫You'll see that it's preparing, which means it's basically downloading that image from the registry
‫to the nodes, and then it gets ready and then it's running.
‫There we go, we're done.
‫If I pull, you'll notice from the top, it's now showing the port 80 because it's a new service, and you'll
‫see that I have it here and it's working.
‫What's interesting about this is that when you're in a swarm, you cannot use an image that's only
‫on one node,
‫right?
‫A swarm has to be able to pull images on all nodes from some repository
‫in a registry that they can all reach. I didn't mention that in the swarm section, but it's an
‫important point because that means that you can't just build an image of your own on a local, like let's say
‫in this case manager1, and manager2 isn't going to be able to go over to manager1 and get it,
‫right?
‫They all have to do push and pulls from a central repository somewhere.
‫But because I ran the registry as a service here, they can all know how to access 127 zero zero one,
‫and then the routing mesh will actually steer them towards the correct container, wherever that registry
‫is running on one of the nodes, and then it'll pull that nginx image to all the nodes as they need
‫to be there.
‫...
‫If you did a docker service ps nginx, you'll see that there's one running on each node,
‫and you'll see that the image it's using is the one from our registry.
‫OK, so that's it for just showing off how Swarm is very similar with Docker Registry.
‫At the end we kind of mentioned, that new tidbit, that you need to make sure that your images that
‫you use in a swarm are just accessible in whatever registry they're going to be in.
‫They have to be accessible by all nodes. That that should be obvious, right, because the nodes can't
‫share images with each other. They actually all have to pull them from a registry
‫and so they all have to be able to reach it.
‫It just so happens that a routing mesh makes it much easier to run that.
‫Just as a last little ProTip, if you don't have to run your own registry, as cool it might be to
‫do so, just use one of the hosted ones on the Internet.
‫...
‫They're redundant.
‫They've got monitoring and all the proper stuff involved with managing the storage.
‫They're usually, especially if you're doing open source,
‫most of them are free.
‫If you're doing it for private reasons and need to store private images, most of them are very reasonable
‫cost, I mean very low cost to store your images.
‫So whether you use an AWS or Quay or Docker Hub or a lot of the options out there, I would say
‫try those first and only use your own registry if you really have some sort of, maybe, offline requirement
‫where it has to be available without the Internet, or if there is just some restriction of security that
‫you really can't use any hosted platform. Because it really just is one of those things where it's a utility
‫and it's great when you can just rely on someone else to solve that problem for you.
‫So I hope you play around with it and have some fun.
‫Now that you don't this lecture, remember to clean up so you can start with a fresh slate on the
‫next lecture.