‫...
‫Now we're going to start the actual registry. We've been talking about it for a while,
‫so let's actually do something with it.
‫The registry is actually really just an HTTPS server like we've talked about.
‫It runs on port 5000 by default.
‫What we're going to do is we're going to start it and then we're going to re-tag an existing image
‫that we have, that we actually got from Docker Hub. That's how you actually change where the registry,
‫which registry is going to be used rather, is you're actually going to re-tag existing images. Then
‫we're going to remove that image from our local cache and we're going to pull it down from the registry
‫after we pushed it up there. Then we're going to actually stop and recreate the registry to show how
‫you can change the storage.
‫In our case, we're just going to use local storage,
‫but there are lots of storage options that we'll talk about. I want to make a real quick note on
‫the registry and how it prefers TLS. Out of the box, Docker will not talk to any registry unless
‫it's running proper HTTPS security.
‫Right?
‫It wants to make sure that your authentication is encrypted and that anything else that's passed is
‫trusted.
‫So we call this Secure by Default.
‫Right? You've probably heard that before. It actually won't talk with the registry we're going to create
‫unless we're creating it on the local hosts, which we are.
‫That's how we're going to do it, is just running on our local host.
‫So that's easy.
‫We don't actually have to worry about TLS just to test this thing out of the box because, like most
‫websites, registry doesn't come with TLS built in.
‫You have to usually create your own certificate.
‫But, if you're going to do self-signed certificates for your registry or maybe you're going to run it
‫remotely without
‫TLS, which I don't encourage you to do but in case you need to, there's actually an insecure-registry
‫option that you would have to enable in the engine.
‫We're not going to cover that here.
‫But just to know, that in production, if you ever need to do a self-signed certificate, that you would
‫just need to enable that. You'll get a good error back from Docker, it'll say: "I can't talk to this registry
‫because I don't trust it." kind of thing,
‫if you try to do that.
‫Today, we're just going to run it with regular HTTP on port 5000.
‫Back to my local machine and do a docker container run -d -p 5000, and it defaults to 5000 in
‫the container,
‫and I'll just call it registry. Then we're using an image registry.
‫If I do a docker container ls, you'll see that it's running. In order to use it,
‫we actually use tags.
‫If you remember with our images with Docker Hub, we had to put them in the format of account name
‫and repository name but that's for Docker Hub. For any other registry,
‫we actually need to label it with the host in there as well.
‫I'm actually going to pull something called hello-world, because it's nice and small. When we run it,
‫it just spits out some text that basically validates that that container ran, perfect for this nice
‫little example. What I need to do in order to push it to my local registry is I need to give it another tag
‫that tells my daemon where it needs to send it.
‫We use docker tag and then the image I need to tag and then where I want to tag it to.
‫So 127.0.0.1:5000,
‫I have to put the port in there and then
‫hello-world.
‫This would be the equivalent of making my own official image at the root of my local registry.
‫If I do a docker image ls, you see the hello-world here has two tags and it's the same image ID because
‫all I did was give it another tag.
‫But then if I do a docker push, it won't actually push to Docker Hub, it will see that there is an IP
‫and port there and push up to my local registry.
‫Now let's remove our local copies so docker image remove and docker image.
‫OK.
‫Oh. Right.
‫Can't remove the image because we've got to get rid of that container first.
‫So docker container rm, and that's the container that ran hello-world,
‫now I can remove the image.
‫There we go.
‫OK so now if I do a docker image ls, I'm sure that I don't have it, right? I don't have that image.
‫Now I can do a docker pull from that same location.
‫There we go.
‫I pull down that image.
‫The first thing, if you're going to run your own registry for your own reasons,
‫the first thing you want to do is use a volume to store the data.
‫In this case, we could delete the registry and use a volume to do the same thing.
‫If I was in this directory where I'm registry-sample-1, I could do a docker container kill registry,
‫docker container
‫rm registry.
‫All right.
‫So we've cleaned up our registry container. Let's make it again docker container run d port 5000,
‫call it registry again. This time we're gonna give it a volume, and we're going to use the pwd trick
‫to give our current working directory,
‫and then I'm going to put a subdirectory in here of registry data. That needs to go to var lib registry.
‫The last part is we're using the registry image.
‫This is technically a new registry with a new database.
‫If you did an ll on the registry data, there wouldn't be anything there yet, but if I took the image
‫we just did a while ago and pulled it back down,
‫you'll see we have the hello-world still there.
‫If I do a docker push again, it should push it right back up there.
‫Now if I do an ll and the registry data directory, you'll see some information in there. I just
‫did a tree command
‫that may not be on your operating system but you don't actually have to run if you don't want. It's a common
‫Linux tool that would show me all the different paths here. You'll see that it actually breaks things
‫down into the data, or blobs, which is the actual binaries that are inside the image, then the
‫metadata around it, which is the manifest, and the tags and such. Everything is in their own SHA directories
‫because you've got multiple layers going on here.
‫It's not really particularly useful for us to dig around in there but it's interesting to see.
‫So there you go.
‫That's the basics of running a registry on your local machine.
‫Then next, we'll need to secure it with some TLS and then enable some authentication.
‫All right. That's the basics of running a Docker registry.
‫Here are the major commands that we ran in this lecture. You might want to pause here if you wanted
‫to write any down or make sure that yours are correct.
‫Now that you're done with this lecture, remember to clean up so you can start with a fresh slate
‫on the next lecture.