#TechBite: Docker Registry
What? Why? How?
Welcome to this month's TechBite. Please be safe and stay healthy during and after the COVID-19 outbreak. ❤️
In this TechBite, we will be looking at the Docker Registry. What it is, Why does it exist at all and of course how we use it.
What? 🤔
What is Docker Registry?
Before we look at the definition for Docker Registry, let us consider the following
- you have just built your Docker image using
docker build
- you want to push (using
docker push
) to storage which you fully manage and control - other than being able to manage this storage, you want to be able to integrate this image storage with other processes (or scripts)
Now how do you go about achieving this? 🤔
Yes, you can use Docker Hub
, which in itself is a storage service provided by Docker for storing and sharing images. But with this, you lose the fully manage and control bit of your requirement.
So how do we pull this off? Docker Registry!
Now, back our initial question What is Docker Registry?
In simple terms, the Docker Registry is a central location where we can store and distribute our docker images. A well-known example of this is the Docker Hub.
Now, that we know what Docker Registry is, let's move on to Why.
Why? 😖
Why do we even need Docker Registry?
Why would we need Docker Registry when we have Docker Hub available to us?
A few reasons why we might need Docker Registry include (not an exhaustive list 😃)
- Have and manage your own image distribution pipeline on an isolated network;
- Have full control where your images are being stored;
- Integrate with and complement your CI/CD pipeline.
So how can we use Docker Registry?
How? 🤔
In its simplest form, we can start our Docker Registry by running the below docker run
command
docker run -d -p 5000:5000 --restart=always --name myregistry registry:2.7.1
Okay now that we have created our registry container, how do we push images to our new registry?
To answer this question, we will need to have an image (Wow! Really!?! 🙄)
In creating an image, we will be using the java-for-docker-blog-post
project to build our image. See REAME.md for how to build the project and image.
Now, that we have followed instructions from here and created our image lets
- Tag it to point to our newly created
myregistry
docker image tag dockerblogposts/java-example:apr-2020 localhost:5000/dockerblogposts/java-example:apr-2020
- Push our tagged image to
myregistry
docker push localhost:5000/dockerblogposts/java-example:apr-2020
- Pull just pushed image from
myregistry
instead of Docker Hub
docker pull localhost:5000/dockerblogposts/java-example:apr-2020
- Run our newly pulled image from
myregistry
docker run -d -p 8099:8095 --name docker-blog-post localhost:5000/dockerblogposts/java-example:apr-2020
Whoa! This is good. I can have my own private registry and control stuff. Great stuff! But how do I secure it? Can I deploy it on a server as localhost
is limited? 🤔 🤔.
We will be looking at these questions in a later post. 🚀
As always thanks for reading and I do look forward to your comments/feedback.